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

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