added basic bot functionality.
This commit is contained in:
51
eve_auth/management/commands/discord_bot.py
Normal file
51
eve_auth/management/commands/discord_bot.py
Normal file
@@ -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)
|
||||||
@@ -3,4 +3,5 @@ requests
|
|||||||
django-allauth
|
django-allauth
|
||||||
django-bootstrap4
|
django-bootstrap4
|
||||||
python-dateutil
|
python-dateutil
|
||||||
bleach
|
bleach
|
||||||
|
git+https://github.com/Rapptz/discord.py@1863a1c#egg=discord.py
|
||||||
|
|||||||
Reference in New Issue
Block a user