-
Notifications
You must be signed in to change notification settings - Fork 0
/
hylkaa.py
executable file
·66 lines (54 loc) · 2.49 KB
/
hylkaa.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/python3 -u
import os
import time
import discord
from dotenv import load_dotenv
from discord.ext import commands
import asyncio
import mysql.connector
from datetime import date
load_dotenv()
intents = discord.Intents.all()
client = commands.Bot(command_prefix='!', intents=intents)
mydb = mysql.connector.connect(
host="localhost",
user="root",
password=os.getenv('db_password'),
database="salaseura"
)
mycursor = mydb.cursor()
@client.event
async def on_ready():
print('hylkaa started on bot {0.user}'.format(client))
@client.command()
async def hylkaa(ctx, user: discord.Member):
load_dotenv()
guest_role = discord.utils.get(ctx.guild.roles, name=os.getenv('guest_role'))
probation_role = discord.utils.get(ctx.guild.roles, name=os.getenv('probation_role'))
member_role = discord.utils.get(ctx.guild.roles, name=os.getenv('member_role'))
member_role2 = discord.utils.get(ctx.guild.roles, name=os.getenv('member_role2'))
member_role3 = discord.utils.get(ctx.guild.roles, name=os.getenv('member_role3'))
mod_role = discord.utils.get(ctx.guild.roles, name=os.getenv('mod_role'))
announce_channel = discord.utils.get(ctx.guild.channels, name=os.getenv('announce_channel'))
commands_channel = discord.utils.get(ctx.guild.channels, name=os.getenv('commands_channel'))
today=date.today()
if ctx.channel == commands_channel:
if mod_role in ctx.author.roles:
if probation_role in user.roles:
await user.remove_roles(probation_role)
await user.add_roles(guest_role)
await ctx.send("<@!" + str(user.id) + "> ei ole enää Tulokas ja on palautettu vieraaksi " + str(today.strftime("%d.%m.%y")))
mycursor = mydb.cursor()
mycursor.execute("DELETE FROM members WHERE user_id=" + str(user.id))
mydb.commit()
else:
await ctx.send("Virhe! Tätä komentoa voi käyttää vain käyttäjiin, joilla on " + str(probation_role) + " -rooli.")
else:
await ctx.send("Virhe! Tätä komentoa voi käyttää vain käyttäjät, joilla on <@&" + str(mod_role.id) + "> -rooli.")
else:
await ctx.send("Virhe! Tätä komentoa voi käyttää vain kanavalla <#" + str(commands_channel.id) + ">.")
@hylkaa.error
async def hylkaa_error(ctx, error):
if isinstance(error, discord.ext.commands.errors.MissingRequiredArgument):
await ctx.send("Käyttö: !hylkaa @käyttäjä")
client.run(os.getenv('TOKEN'))