]> code.communitydata.science - coldcallbot-discord.git/blob - coldcallbot.py
Adding support for classes which each use their own category. Moving key into a confi...
[coldcallbot-discord.git] / coldcallbot.py
1 #!/usr/bin/env python3
2
3 from coldcall import ColdCall
4 import re
5 import discord
6 import config
7
8 ## create the coldcall object
9 cc = ColdCall()
10
11 class ColdCallBot (discord.Client):
12     async def on_ready(self):
13         print(f'Logged on as {self.user}! Ready for class!')
14
15     async def on_message(self, message, voice_channel = 'Class Sessions'):
16         if message.author == self.user:
17             return
18
19         if message.content.startswith('$next'):
20             if message.channel.category:
21                 if cc.course != message.channel.category:
22                     cc.update_course(message.channel.category)
23             classroom = [x for x in message.guild.voice_channels if x.name == voice_channel and x.category_id == message.channel.category_id][0]
24
25             present_students = []
26             for member in classroom.members:
27                 if 'Students' in [r.name for r in member.roles]:
28                     present_students.append(re.sub(r'^(.*)\#.*$', r'\1', member.name))
29
30             # print who is online
31             print(f'currently online: {",".join(present_students)}')
32
33             if len(present_students) < 1:
34                 msg_text = "I don't see any students currently in the Classroom Voice channel!"
35             else:
36                 if cc is None:
37                     print('hi')
38                 msg_text = cc.coldcall(present_students)
39                 
40             await message.channel.send(msg_text)
41
42 # this is necessary to get information about who is online
43 intents = discord.Intents.default()
44 intents.members = True
45 intents.presences = True
46
47 ccb = ColdCallBot(intents=intents)
48 ccb.run(config.key)

Community Data Science Collective || Want to submit a patch?