-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
executable file
·100 lines (85 loc) · 4.32 KB
/
bot.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/python3
import os
import discord
from discord.ext import commands
from dotenv import load_dotenv
import time
import requests
import datetime
banTime = 300
load_dotenv()
TOKEN = os.getenv("DISCORD_TOKEN")
intents = discord.Intents.all()
client = discord.Client(intents=intents)
class Bot(commands.Bot):
def __init__(self, command_prefix):
intents = discord.Intents.all()
commands.Bot.__init__(self, command_prefix=command_prefix, setlf_bot=False, intents=intents)
self.remove_command("help")
self.load_commands()
self.help_message = "Vítej na ZISKordu. Pokud chceš znát deadline, napiš do channelu !deadline. Pokud potřebuješ něco jiného, neboj se zeptat mě, nebo organizátorů.\n"
async def process_commands(self, message):
ctx = await self.get_context(message)
await self.invoke(ctx)
def load_commands(self):
@self.command(name="help")
async def _help(ctx):
message = self.help_message
if 'Organizátor' in map(lambda x: x.name, ctx.message.author.roles):
message += "Příkazem !forward mi můžeš napsat zprávu a channel, kde tvou zprávu za tebe vyřídím. (Navštiv channel bot-forward pro více info.)\n"
await ctx.channel.send(content=message)
@self.command(name="deadline")
async def deadline(ctx):
ENDPOINT = '/meta/'
for year in range(23, 33):
for series in range(1, 5):
for task in range(1, 5):
id = str(year) + '0' + str(series) + '0' + str(task)
resp = requests.get("https://api.zisk-go.com/tasks/meta?id=" + id).json()
if 'error' in resp:
await ctx.channel.send("Request on zisk server went wrong")
if 'Organizátor' in map(lambda x: x.name, ctx.message.author.roles):
await ctx.channel.send(resp['error'])
return
deadline = datetime.datetime.fromisoformat(resp['deadline'])
if datetime.datetime.now() < deadline:
await ctx.channel.send("Nejbližší deadline je: " + deadline.strftime("%d. %m. %Y v %H:%M") + ".")
return
@self.command(name="forward")
@commands.has_role('Organizátor')
async def forward(ctx, channelName, msg):
channel = discord.utils.get(ctx.guild.channels, name=channelName)
if channel is None:
await ctx.channel.send("Channel [" + channelName +"] was not found.")
else:
await channel.send(msg)
@self.event
async def on_message(message):
await self.process_commands(message)
ctx = await self.get_context(message)
if message.content == "kakakah":
# trollíme Kubu
await ctx.channel.send("Co se to snažíš vytvořit, že to má reagovat na kakakah?")
if ctx.channel.name.endswith('memes'):
pic_ext = ['.jpg','.png','.jpeg']
for file in message.attachments:
for ext in pic_ext:
if file.filename.endswith(ext):
resp = requests.get('https://api.zisk-go.com/discussion/thread?channel=memes&channelType=memes')
data = {
'id': None,
'author': None,
'content': message.content,
#'details': 'https://api.zisk-go.com/tasks/files/getMeme?fileName=' + resp_filename,
'details': file.url,
'creationDate': None,
'threadId': int(resp.json()['id']),
'children': []
}
resp = requests.post('https://api.zisk-go.com/discussion/post', json=data,
headers={'Content-type': 'application/json', 'Accept': 'application/json'
}
)
print(resp.json())
bot = Bot("!")
bot.run(TOKEN)