]> code.communitydata.science - coldcallbot-discord.git/blobdiff - coldcallbot.py
Adding support for classes which each use their own category. Moving key into a confi...
[coldcallbot-discord.git] / coldcallbot.py
index 392028a0e82ef6484dd0b098ab9ac3237b8f4948..fd7669f7ceea6414baedb2677d1535755261811d 100755 (executable)
@@ -3,6 +3,7 @@
 from coldcall import ColdCall
 import re
 import discord
 from coldcall import ColdCall
 import re
 import discord
+import config
 
 ## create the coldcall object
 cc = ColdCall()
 
 ## create the coldcall object
 cc = ColdCall()
@@ -11,13 +12,16 @@ class ColdCallBot (discord.Client):
     async def on_ready(self):
         print(f'Logged on as {self.user}! Ready for class!')
 
     async def on_ready(self):
         print(f'Logged on as {self.user}! Ready for class!')
 
-    async def on_message(self, message):
+    async def on_message(self, message, voice_channel = 'Class Sessions'):
         if message.author == self.user:
             return
 
         if message.content.startswith('$next'):
         if message.author == self.user:
             return
 
         if message.content.startswith('$next'):
-            classroom = discord.utils.get(message.guild.voice_channels, name='Classroom Voice')
-            
+            if message.channel.category:
+                if cc.course != message.channel.category:
+                    cc.update_course(message.channel.category)
+            classroom = [x for x in message.guild.voice_channels if x.name == voice_channel and x.category_id == message.channel.category_id][0]
+
             present_students = []
             for member in classroom.members:
                 if 'Students' in [r.name for r in member.roles]:
             present_students = []
             for member in classroom.members:
                 if 'Students' in [r.name for r in member.roles]:
@@ -29,6 +33,8 @@ class ColdCallBot (discord.Client):
             if len(present_students) < 1:
                 msg_text = "I don't see any students currently in the Classroom Voice channel!"
             else:
             if len(present_students) < 1:
                 msg_text = "I don't see any students currently in the Classroom Voice channel!"
             else:
+                if cc is None:
+                    print('hi')
                 msg_text = cc.coldcall(present_students)
                 
             await message.channel.send(msg_text)
                 msg_text = cc.coldcall(present_students)
                 
             await message.channel.send(msg_text)
@@ -39,5 +45,4 @@ intents.members = True
 intents.presences = True
 
 ccb = ColdCallBot(intents=intents)
 intents.presences = True
 
 ccb = ColdCallBot(intents=intents)
-ccb.run('CHANGEME')
-
+ccb.run(config.key)

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