From 11af7e53f1361c3825012efa718738cfae06633d Mon Sep 17 00:00:00 2001
From: dnns01 <mail@dnns01.de>
Date: Thu, 1 Oct 2020 11:21:21 +0200
Subject: [PATCH] Fixed issue with divide by zero error in the rare case, where
 somebody sends !pipi at a moment, where no chatter was recognized by twitch
 so far. Added !hauge-command, that sends a link to github into the twitch
 chat

---
 hausgeist.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/hausgeist.py b/hausgeist.py
index be20704..1b77a41 100644
--- a/hausgeist.py
+++ b/hausgeist.py
@@ -1,9 +1,9 @@
 import asyncio
 import os
+import random
 import time
 
 import redis
-import random
 from dotenv import load_dotenv
 from twitchio.dataclasses import Context, Message, Channel
 from twitchio.ext import commands
@@ -87,8 +87,10 @@ if useRedis and r:
 
 def get_percentage(part, total):
     """ Calculate percentage """
+    if total != 0:
+        return round(part / total * 100, 1)
 
-    return round(part / total * 100, 1)
+    return 0
 
 
 async def notify_pipi(ctx, use_timer=True, message=None):
@@ -200,6 +202,12 @@ async def cmd_pipimeter(ctx):
         await notify_pipi(ctx, use_timer=False)
 
 
+@bot.command(name="hauge-commands", aliases=["Hauge-commands", "haugebot-commands", "Haugebot-commands"])
+async def cmd_haugebot_commands(ctx):
+    await ctx.send(
+        "Eine Liste mit den Commands des HaugeBot findest du unter: https://github.com/dnns01/TwitchHausGeist/blob/master/README.md")
+
+
 @bot.event
 async def event_message(message):
     global votes
@@ -403,7 +411,7 @@ async def cmd_giveawaydraw(ctx):
             await send_me(ctx, f"Es wurde aus {entry_count} Einträgen ausgelost. Und der Gewinner ist... @{winner}", VOTE_COLOR)
         else:
             await send_me(ctx, "Es muss Einträge geben, damit ein Gewinner gezogen werden kann.", VOTE_COLOR)
-       
+
 
 @bot.command(name="giveaway-reset")
 async def cmd_giveawayreset(ctx):
-- 
GitLab