forked from namishkhanna/hacktoberfest2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BelleBot.py
75 lines (57 loc) · 1.92 KB
/
BelleBot.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
"""
Archie's BelleBot
She can tell you exactly how many days are left before the end of hacktoberfest-2020
You will need discord.py to run this bot. You can install it via pip using 'pip install discord.py'
"""
from sys import exit
import datetime
from discord.ext import commands
from discord.ext.commands import Bot, when_mentioned_or
from discord import DMChannel, Intents
from aiohttp import ClientSession
class Belle(Bot):
def __init__(self, *args, **options):
super().__init__(*args, **options)
self.session = None
async def start(self, *args, **kwargs):
self.session = ClientSession()
await super().start('The discord token goes here!', *args, **kwargs)
async def close(self):
await self.session.close()
await super().close()
client = Belle(
command_prefix=when_mentioned_or('Belle, '),
intents=Intents.default(),
max_messages=1000
)
@client.event
async def on_ready():
print('I\'m online!')
return True
@client.event
async def on_message(msg):
if isinstance(msg.channel, DMChannel):
return
if client.user.mentioned_in(msg):
end_of_hacktoberfest = datetime.datetime(2020, 10, 31)
now = datetime.datetime.utcnow()
discard = datetime.timedelta(minutes=now.minute % 10,
seconds=now.second,
microseconds=now.microsecond)
now -= discard
if discard >= datetime.timedelta(minutes=5):
now += datetime.timedelta(minutes=10)
delta = end_of_hacktoberfest - now
await msg.channel.send(f'Hacktoberfest 2020 ends in {delta} hours!')
await client.process_commands(msg)
@commands.is_owner()
@client.command(
name='shutdown',
brief='A little kill switch in case robots take over!',
hidden=True
)
async def shutdown(ctx):
await ctx.send('Bye bye!')
exit(0)
if __name__ == '__main__':
client.run()