diff --git a/eve_auth/management/commands/discord_bot.py b/eve_auth/management/commands/discord_bot.py new file mode 100644 index 0000000..6f7bd2a --- /dev/null +++ b/eve_auth/management/commands/discord_bot.py @@ -0,0 +1,51 @@ +import logging +import discord +import asyncio + +from django.core.management.base import BaseCommand + +logger = logging.getLogger('discord') + + +# https://discordapp.com/oauth2/authorize?client_id=XXXXXXXXXXXX&scope=bot +TOKEN = 'XXXXXXXXXXXXXXXXX' + +client = discord.Client() + + +@client.event +async def on_message(message): + # we do not want the bot to reply to itself + if message.author == client.user: + return + + if message.content.startswith('!hello'): + msg = 'Hello {0.author.mention}'.format(message) + await client.send_message(message.channel, msg) + + +async def check_groups(): + default_channel = None + for channel in client.get_all_channels(): + if channel.is_default: + default_channel = channel + while True: + await client.send_message(default_channel, 'Periodic') + await asyncio.sleep(10) + + +@client.event +async def on_ready(): + print('Logged in as') + print(client.user.name) + print(client.user.id) + print('------') + asyncio.Task(check_groups()) + + +class Command(BaseCommand): + def __init__(self): + super().__init__() + + def handle(self, *args, **options): + client.run(TOKEN) diff --git a/requirements.txt b/requirements.txt index de8e9e4..18fa7d1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,5 @@ requests django-allauth django-bootstrap4 python-dateutil -bleach \ No newline at end of file +bleach +git+https://github.com/Rapptz/discord.py@1863a1c#egg=discord.py