Skip to content

Commit

Permalink
fixed default buffer, added alerts, refactored file upload filter
Browse files Browse the repository at this point in the history
  • Loading branch information
RduMarais committed May 9, 2022
1 parent 6667567 commit 2712abc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
13 changes: 13 additions & 0 deletions pollsite/poll/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,19 @@ def subscribe_to_chat(self):
self.channel_name
)

def send_bot_alert(self,revolutionbot):
print('debug : sent bot alert')
if(self.meeting.platform != 'IRL'):
if(settings.DEBUG):
print('debug : sending revolution alert')
message_out = {
'message' : "bot-alert",
'content': revolutionbot.message,
'alert': revolutionbot.alert.url,
}
self.send(text_data=json.dumps(message_out))



### LIVE STREAMS
# the polling process is defined in another class for clarity of threading
Expand Down
12 changes: 4 additions & 8 deletions pollsite/poll/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,15 @@ class RevolutionBot(models.Model):
threshold_number = models.IntegerField(_('Number of commands to be sent'),default=5)
is_active = models.BooleanField(_('is this command activated'),default=False)
meeting = models.ForeignKey(Meeting,on_delete=models.SET_NULL,null=True)
buffer = models.JSONField(_('internal state of the bot'),default=dict({'triggers':[],'last_revolution':[]}),encoder=DjangoJSONEncoder)
buffer = models.JSONField(_('internal state of the bot'),default=dict({'triggers':[],'last_revolution':''}),encoder=DjangoJSONEncoder)
# i'd like to add a FileField but I need to validate it
alert = models.FileField(_('Alert video to be displayed'),null=True,blank=True)

def save(self, *args, **kwargs):
def clean(self):
if(self.alert):
file_type = magic.from_buffer(self.alert.open("rb").read(2048),mime=True)
if(file_type == 'video/mp4'):
super(RevolutionBot, self).save(*args, **kwargs)
else:
raise ValidationError({'title': "This file format is not allowed"})
else:
super(RevolutionBot, self).save(*args, **kwargs)
if(file_type != 'video/mp4'):
raise ValidationError({'alert': "This file format is not allowed"})



Expand Down
4 changes: 4 additions & 0 deletions pollsite/poll/twitch_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ def bot_listen(self,message: twitch.chat.Message) -> None:
self.print_message({'sender':settings.TWITCH_NICKNAME,'text':settings.BOT_MSG_PREFIX+revolution[0].message,'source':'t'})
revolution[0].buffer['last_revolution'] = now.isoformat()
revolution[0].buffer['triggers'] = []
print('debug : reset buffer')
if(revolution[0].alert):
print('debug : will send alert')
self.meetingConsumer.send_bot_alert(revolution[0])

revolution[0].buffer['triggers'].append({'name':message.sender,'time':now.isoformat()})
print('debug : added last to buffer')
Expand Down

0 comments on commit 2712abc

Please sign in to comment.