diff --git a/haugebot_twitch/haugebot.py b/haugebot_twitch/haugebot.py index ce9d161d0552ae353eda1edefc79a16f242e2a1d..a13dd5ee63fd22a612a59d6d6d395877665eaf1c 100644 --- a/haugebot_twitch/haugebot.py +++ b/haugebot_twitch/haugebot.py @@ -8,6 +8,7 @@ from twitchio.ext.commands import Context, Bot from vote_cog import VoteCog from wusstest_du_schon import WusstestDuSchon from wordcloud import Wordcloud +from whispers import Whispers class HaugeBot(Bot, ABC): @@ -24,6 +25,7 @@ class HaugeBot(Bot, ABC): self.add_cog(VoteCog(self)) self.add_cog(WusstestDuSchon(self)) self.add_cog(Wordcloud(self)) + self.add_cog(Whispers(self)) @staticmethod async def send_me(ctx, content): diff --git a/haugebot_twitch/whispers.py b/haugebot_twitch/whispers.py new file mode 100644 index 0000000000000000000000000000000000000000..a7f1bbe73befe71eb68f7d039fa37ed826ad8af9 --- /dev/null +++ b/haugebot_twitch/whispers.py @@ -0,0 +1,24 @@ +import sqlite3 +from datetime import datetime + +from twitchio.ext import commands + + +class Whispers(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.Cog.event() + async def event_message(self, message): + # make sure the bot ignores itself and nightbot + if not message.author or message.author.name.lower() in [self.bot.NICK.lower(), + 'nightbot'] or message.channel is not None: + return + + conn = sqlite3.connect("db.sqlite3") + c = conn.cursor() + c.execute( + "INSERT INTO haugebot_web_whisper(author, content, received_at) VALUES (?, ?, ?)", + (message.author.name, message.content, datetime.now())) + conn.commit() + conn.close() diff --git a/haugebot_web/migrations/0007_whisper.py b/haugebot_web/migrations/0007_whisper.py new file mode 100644 index 0000000000000000000000000000000000000000..b88acf1593527fbd5de47fb1e1d9c4284f6efe5f --- /dev/null +++ b/haugebot_web/migrations/0007_whisper.py @@ -0,0 +1,24 @@ +# Generated by Django 3.2.10 on 2021-12-22 09:49 + +import datetime +from django.db import migrations, models +import django + + +class Migration(migrations.Migration): + + dependencies = [ + ('haugebot_web', '0006_auto_20211220_0048'), + ] + + operations = [ + migrations.CreateModel( + name='Whisper', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('author', models.TextField(max_length=50)), + ('content', models.TextField(max_length=500)), + ('received_at', models.DateTimeField(default=django.utils.timezone.now)), + ], + ), + ] diff --git a/haugebot_web/models.py b/haugebot_web/models.py index ec339d79a0ae66948da54b5c5d93be2ee4d1f751..ec18009812268bf570812db15363c963198956dd 100644 --- a/haugebot_web/models.py +++ b/haugebot_web/models.py @@ -1,6 +1,7 @@ import os from django.db import models +from django.utils import timezone from haugebot_web import twitch_api from .managers import TwitchUserManager @@ -62,3 +63,9 @@ class TwitchUser(models.Model): return twitch_api.is_mod(self, broadcaster) except TwitchUser.DoesNotExist: return False + + +class Whisper(models.Model): + author = models.TextField(max_length=50) + content = models.TextField(max_length=500) + received_at = models.DateTimeField(default=timezone.now)