-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscord_handler.py
49 lines (42 loc) · 1.83 KB
/
discord_handler.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
import os
from function import *
import discord
from discord.ext import commands
import html
from datetime import datetime
from datetime import timedelta
from datetime import timezone
from markdownify import markdownify
dcbot = discord.ext.commands.Bot(command_prefix="%")
@dcbot.command()
async def ping(ctx):
await ctx.send(f"{dcbot.latency*1000} ms")
@dcbot.command()
async def due(ctx):
await ctx.reply(embed=discord.Embed(title="Fetching Data....", color=0x00ff59))
data = grab_data()
if len(data) > 0:
for i in data:
embed = discord.Embed(title=(i['name']).replace(" is due", ""),
url=html.unescape(i['action']['url']),
description=markdownify(i['description']), color=0x00ff59)
embed.set_author(name=i['course']['fullname'],
url=i['course']['viewurl'])
embed.add_field(name="Due date",
value=datetime.fromtimestamp(i['timesort'], tz=timezone(timedelta(hours=8))).strftime(
'%Y-%m-%d %H:%M:%S'), inline=True)
embed.add_field(name="Days remaining", value=str((datetime.fromtimestamp(i['timesort'], tz=timezone(
timedelta(hours=8))) - datetime.now(timezone(timedelta(hours=8)))).days), inline=True)
await ctx.send(embed=embed)
else:
await ctx.reply(embed=discord.Embed(title="No recent events.", color=0x00ff59))
@dcbot.event
async def on_message(message):
# Ignore private messages
if message.author == dcbot.user:
return
if isinstance(message.channel, discord.DMChannel):
print(message.author.name + " send the DM: " + message.content)
await message.channel.send('Private message is disabled.')
return
await dcbot.process_commands(message)