From b077bd1d50597baca34a6feb6152a8aa7e63a188 Mon Sep 17 00:00:00 2001
From: dnns01 <git@dnns01.de>
Date: Sun, 12 Jun 2022 20:44:54 +0200
Subject: [PATCH] Fix wordcloud and change vote results to use twitch
 announcements

---
 haugebot/consumers.py        | 3 +++
 haugebot/settings.py         | 2 ++
 haugebot_twitch/haugebot.py  | 9 +++++++++
 haugebot_twitch/vote_cog.py  | 2 +-
 haugebot_twitch/wordcloud.py | 4 ++--
 haugebot_web/views.py        | 2 +-
 6 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/haugebot/consumers.py b/haugebot/consumers.py
index ce7c24e..d881972 100644
--- a/haugebot/consumers.py
+++ b/haugebot/consumers.py
@@ -4,6 +4,9 @@ import os
 from asgiref.sync import async_to_sync
 from channels.generic.websocket import WebsocketConsumer
 from wordcloud import WordCloud
+from dotenv import load_dotenv
+
+load_dotenv()
 
 secret = os.getenv("WORDCLOUD_SECRET")
 words = {}
diff --git a/haugebot/settings.py b/haugebot/settings.py
index 07a88fe..1947db9 100644
--- a/haugebot/settings.py
+++ b/haugebot/settings.py
@@ -31,6 +31,8 @@ DEBUG = os.getenv("DJANGO_DEBUG") == "True"
 
 ALLOWED_HOSTS = [os.getenv("DJANGO_ALLOWED_HOST1"), os.getenv("DJANGO_ALLOWED_HOST2"), "127.0.0.1"]
 
+CSRF_TRUSTED_ORIGINS = ["https://" + os.getenv("DJANGO_ALLOWED_HOST2")]
+
 AUTHENTICATION_BACKENDS = [
     'haugebot_web.auth.TwitchAuthenticationBackend',
 ]
diff --git a/haugebot_twitch/haugebot.py b/haugebot_twitch/haugebot.py
index a13dd5e..fb1785b 100644
--- a/haugebot_twitch/haugebot.py
+++ b/haugebot_twitch/haugebot.py
@@ -27,6 +27,15 @@ class HaugeBot(Bot, ABC):
         self.add_cog(Wordcloud(self))
         self.add_cog(Whispers(self))
 
+    @staticmethod
+    async def send_announce(ctx, content):
+        """ Change Text color to color and send content as message """
+
+        if type(ctx) is Context or type(ctx) is Channel:
+            await ctx.send(f".announce {content}")
+        elif type(ctx) is Message:
+            await ctx.channel.send(f".announce {content}")
+
     @staticmethod
     async def send_me(ctx, content):
         """ Change Text color to color and send content as message """
diff --git a/haugebot_twitch/vote_cog.py b/haugebot_twitch/vote_cog.py
index 9a3d7ec..c420e82 100644
--- a/haugebot_twitch/vote_cog.py
+++ b/haugebot_twitch/vote_cog.py
@@ -47,7 +47,7 @@ class VoteCog(commands.Cog):
         output += f'Endergebnis' if final_result else f'Zwischenergebnis'
         output += f' mit insgesamt {len(self.votes)} abgegebenen Stimmen'
 
-        await self.bot.send_me(message, output)
+        await self.bot.send_announce(message, output)
 
     def get_votes(self):
         """analyzes the votes-dict and counts the votes"""
diff --git a/haugebot_twitch/wordcloud.py b/haugebot_twitch/wordcloud.py
index c80e677..f0c0f1e 100644
--- a/haugebot_twitch/wordcloud.py
+++ b/haugebot_twitch/wordcloud.py
@@ -57,8 +57,8 @@ class Wordcloud(commands.Cog):
             else:
                 self.running = False
         else:
-            # self.words[ctx.author.name] = phrase
-            self.words[phrase] = phrase
+            self.words[ctx.author.name] = phrase
+            # self.words[phrase] = phrase
 
     def sum_words(self):
         words = {}
diff --git a/haugebot_web/views.py b/haugebot_web/views.py
index 6befda5..c8c9999 100644
--- a/haugebot_web/views.py
+++ b/haugebot_web/views.py
@@ -21,7 +21,7 @@ def home(request):
 @login_required(login_url="/login")
 def wordcloud(request):
     id = os.getenv("DJANGO_WORDCLOUD_LIVE_ID")
-    host = os.getenv("DJANGO_ALLOWED_HOST1")
+    host = os.getenv("DJANGO_ALLOWED_HOST2")
     embed_link = f"{request.scheme}://{host}{reverse('wordcloud_live', args=(id,))}" if request.user.is_broadcaster else ""
     return render(request, "wordcloud.html", {'title': 'Wordcloud', "ws_url": os.getenv("WORDCLOUD_WS_URL"),
                                               "session_key": request.session.session_key, "embed_link": embed_link})
-- 
GitLab