From 22bcb53e1768de1d90454a678243c5ab4b0f3d8c Mon Sep 17 00:00:00 2001 From: Appelsiini1 <37345715+Appelsiini1@users.noreply.github.com> Date: Thu, 15 Apr 2021 01:35:12 +0300 Subject: [PATCH 1/8] Finish nitro tracking - Move embed construction to it's own function - Change texts on embeds - Add TinyCactus easter egg - Fix issue where boosts would get logged more than once - Added boost amount tracking - Fix track status checking not working - Removed test function - Fix for poll function not working properly if no arguments given --- modules/nitro.py | 150 +++++++++++++++++++++++++---------------------- modules/poll.py | 5 +- 2 files changed, 85 insertions(+), 70 deletions(-) diff --git a/modules/nitro.py b/modules/nitro.py index 0414622..c5b5793 100644 --- a/modules/nitro.py +++ b/modules/nitro.py @@ -6,6 +6,55 @@ from constants import DB_F EMOJI = "\N{PARTY POPPER}" +EMOJI2 = "\N{CONFETTI BALL}" +HEART_EMOTE = "\N{SPARKLING HEART}" +SURPRISE_EMOTE = "\N{FACE WITH OPEN MOUTH}" + + +def constructEmbed(message, boosts): + emb = discord.Embed() + + if message.guild.id == 181079344611852288: # TinyCactus easter egg + emote_name = "cheart" + emote_name2 = "cacsurp2" + succ = 0 + try: + for em in message.guild.emojis: + if em.name == emote_name: + H_e = em + succ += 1 + if em.name == emote_name2: + C_s = em + if succ == 2: + break + HeartEmote = str(H_e) + SurpriseEmote = str(C_s) + except Exception: + logging.exception( + "Error occured when getting 'cheart' or 'cacsurp2' emote. Using defaults." + ) + HeartEmote = HEART_EMOTE + SurpriseEmote = SURPRISE_EMOTE + + if boosts == 1: + txt = f"{HeartEmote} {message.guild.name} just got a New Boost by **{message.author.display_name}**! {HeartEmote}" + else: + txt = f"{HeartEmote} {message.guild.name} just got {boosts} ({SurpriseEmote}) New Boosts by **{message.author.display_name}**! {HeartEmote}" + + emb.title = f"{EMOJI} {EMOJI} NEW BOOST! {EMOJI} {EMOJI}" + emb.color = get_hex_colour(cora_eye=True) + if message.type == discord.MessageType.premium_guild_subscription: + emb.description = f"{txt}" + elif message.type == discord.MessageType.premium_guild_tier_1: + emb.description = f"{txt}\n\ + {EMOJI2} {EMOJI} The server has leveled up to Level 1! {EMOJI} {EMOJI2}" + elif message.type == discord.MessageType.premium_guild_tier_2: + emb.description = f"{txt}\n\ + {EMOJI2} {EMOJI} The server has leveled up to Level 2! {EMOJI} {EMOJI2}" + elif message.type == discord.MessageType.premium_guild_tier_3: + emb.description = f"{txt}\n\ + {EMOJI2} {EMOJI} The server has leveled up to Level 3! {EMOJI} {EMOJI2}" + return emb async def trackNitro(message): @@ -16,26 +65,22 @@ async def trackNitro(message): time = datetime.datetime.today().strftime("%d.%m.%Y %H:%M:%S") emb = discord.Embed() - c.execute(f"SELECT * FROM TrackNitro WHERE Guild_ID={guild_id}") + try: + boostAmount = int(message.content) + except Exception: + boostAmount = 1 + + c.execute(f"SELECT * FROM NitroTrack WHERE Guild_ID={guild_id}") track = c.fetchone() - if track[0][1] == 0 or track == None: + # print(track) + if track == None: + print("Here") return - elif track[0][1] == 2: # TODO Only post a notice of the boost but do not track - emb.title = f"{EMOJI} {EMOJI} NEW BOOST! {EMOJI} {EMOJI}" - emb.color = get_hex_colour(cora_eye=True) - if message.type == discord.MessageType.premium_guild_subscription: - emb.description = f"{message.guild.name} just got a new boost by {message.author.display_name}!" - elif message.type == discord.MessageType.premium_guild_tier_1: - emb.description = f"{message.guild.name} just got a new boost by {message.author.display_name}!\n\ - The server has leveled up to Level 1! {EMOJI}" - elif message.type == discord.MessageType.premium_guild_tier_2: - emb.description = f"{message.guild.name} just got a new boost by {message.author.display_name}!\n\ - The server has leveled up to Level 2! {EMOJI} {EMOJI}" - elif message.type == discord.MessageType.premium_guild_tier_3: - emb.description = f"{message.guild.name} just got a new boost by {message.author.display_name}!\n\ - The server has leveled up to Level 3! {EMOJI} {EMOJI} {EMOJI}" + elif track[1] == 2: # TODO Only post a notice of the boost but do not track + emb = constructEmbed(message, boostAmount) try: await message.channel.send(embed=emb) + return except discord.errors.Forbidden: logging.error("Unable to send message due to 403 - Forbidden") emb.clear_fields() @@ -51,14 +96,15 @@ async def trackNitro(message): "SELECT * FROM NitroBoosts WHERE Guild_ID=? AND User_ID=?", (guild_id, booster_id), ) - previousBoosts = c.fetchall() - if len(previousBoosts) == 0 or previousBoosts == None: + previousBoosts = c.fetchone() + # print(previousBoosts) + if previousBoosts == None: c.execute("SELECT Boost_ID FROM NitroBoosts ORDER BY Boost_ID DESC") lastID = c.fetchone() if lastID == None: lastID = 1 else: - lastID += 1 + lastID = lastID[0] + 1 # Boost_ID INT UNIQUE, # User_ID INT, @@ -72,9 +118,10 @@ async def trackNitro(message): try: c.execute( "INSERT INTO NitroBoosts VALUES (?,?,?,?,?,?)", - (lastID, booster_id, guild_id, time, time, 1), + (lastID, booster_id, guild_id, time, time, boostAmount), ) success = 1 + break except sqlite3.IntegrityError: i += 1 lastID += 1 @@ -88,19 +135,7 @@ async def trackNitro(message): await dm_channel.send(embed=emb) return else: - emb.title = f"{EMOJI} {EMOJI} NEW BOOST! {EMOJI} {EMOJI}" - emb.color = get_hex_colour(cora_eye=True) - if message.type == discord.MessageType.premium_guild_subscription: - emb.description = f"{message.guild.name} just got a new boost by {message.author.display_name}!" - elif message.type == discord.MessageType.premium_guild_tier_1: - emb.description = f"{message.guild.name} just got a new boost by {message.author.display_name}!\n\ - The server has leveled up to Level 1! {EMOJI}" - elif message.type == discord.MessageType.premium_guild_tier_2: - emb.description = f"{message.guild.name} just got a new boost by {message.author.display_name}!\n\ - The server has leveled up to Level 2! {EMOJI} {EMOJI}" - elif message.type == discord.MessageType.premium_guild_tier_3: - emb.description = f"{message.guild.name} just got a new boost by {message.author.display_name}!\n\ - The server has leveled up to Level 3! {EMOJI} {EMOJI} {EMOJI}" + emb = constructEmbed(message) try: await message.channel.send(embed=emb) conn.commit() @@ -121,25 +156,13 @@ async def trackNitro(message): (guild_id, booster_id), ) boost = c.fetchone() - boosts = boost[0][5] - newValue = boosts + 1 + boosts = boost[5] + newValue = boosts + boostAmount c.execute( "UPDATE NitroBoosts SET Boosts=?, LatestBoost=? WHERE Guild_ID=? AND User_ID=?", (newValue, time, guild_id, booster_id), ) - emb.title = f"{EMOJI} {EMOJI} NEW BOOST! {EMOJI} {EMOJI}" - emb.color = get_hex_colour(cora_eye=True) - if message.type == discord.MessageType.premium_guild_subscription: - emb.description = f"{message.guild.name} just got a new boost by {message.author.display_name}!" - elif message.type == discord.MessageType.premium_guild_tier_1: - emb.description = f"{message.guild.name} just got a new boost by {message.author.display_name}!\n\ - The server has leveled up to Level 1! {EMOJI}" - elif message.type == discord.MessageType.premium_guild_tier_2: - emb.description = f"{message.guild.name} just got a new boost by {message.author.display_name}!\n\ - The server has leveled up to Level 2! {EMOJI} {EMOJI}" - elif message.type == discord.MessageType.premium_guild_tier_3: - emb.description = f"{message.guild.name} just got a new boost by {message.author.display_name}!\n\ - The server has leveled up to Level 3! {EMOJI} {EMOJI} {EMOJI}" + emb = constructEmbed(message, boostAmount) try: await message.channel.send(embed=emb) conn.commit() @@ -160,8 +183,9 @@ async def Tracking(message): # "!c nitro track [start|stop|notice]" with sqlite3.connect(DB_F) as conn: c = conn.cursor() - arg = message.content.split(" ")[3] + arg = message.content.split(" ")[2] emb = discord.Embed() + # print(arg) if arg.strip() == "start": c.execute(f"SELECT * FROM NitroTrack WHERE Guild_ID={message.guild.id}") trackStatus = c.fetchone() @@ -173,13 +197,13 @@ async def Tracking(message): await message.channel.send(embed=emb) return - elif trackStatus[0][1] == 1: + elif trackStatus[1] == 1: emb.title = "The nitro tracking is already enabled on this server." emb.color = get_hex_colour(error=True) await message.channel.send(embed=emb) return - elif trackStatus[0][1] == 2 or trackStatus[0][1] == 0: + elif trackStatus[1] == 2 or trackStatus[1] == 0: c.execute( f"UPDATE NitroTrack SET Track_YN=1 WHERE Guild_ID={message.guild.id}" ) @@ -200,13 +224,13 @@ async def Tracking(message): await message.channel.send(embed=emb) return - elif trackStatus[0][1] == 0: + elif trackStatus[1] == 0: emb.title = "The nitro tracking is already disabled on this server." emb.color = get_hex_colour(error=True) await message.channel.send(embed=emb) return - elif trackStatus[0][1] == 2 or trackStatus[0][1] == 1: + elif trackStatus[1] == 2 or trackStatus[1] == 1: c.execute( f"UPDATE NitroTrack SET Track_YN=0 WHERE Guild_ID={message.guild.id}" ) @@ -215,7 +239,7 @@ async def Tracking(message): emb.color = get_hex_colour(cora_eye=True) await message.channel.send(embed=emb) return - + elif arg.strip() == "notice": c.execute(f"SELECT * FROM NitroTrack WHERE Guild_ID={message.guild.id}") trackStatus = c.fetchone() @@ -227,13 +251,13 @@ async def Tracking(message): await message.channel.send(embed=emb) return - elif trackStatus[0][1] == 2: + elif trackStatus[1] == 2: emb.title = "The nitro tracking is already disabled on this server." emb.color = get_hex_colour(error=True) await message.channel.send(embed=emb) return - elif trackStatus[0][1] == 0 or trackStatus[0][1] == 1: + elif trackStatus[1] == 0 or trackStatus[1] == 1: c.execute( f"UPDATE NitroTrack SET Track_YN=2 WHERE Guild_ID={message.guild.id}" ) @@ -253,16 +277,4 @@ async def parseNitroAddition(message): async def delNitro(message): - pass - - -async def test(message): - # !c test [] - - id = int(message.content[8:]) - msg = await message.channel.fetch_message(id) - print(msg.system_content) - print(msg.raw_mentions) - print(msg.author) - print(msg.is_system()) - print(msg.type) \ No newline at end of file + pass \ No newline at end of file diff --git a/modules/poll.py b/modules/poll.py index 9f0235e..57bed7a 100644 --- a/modules/poll.py +++ b/modules/poll.py @@ -15,7 +15,10 @@ async def Poll(message): - content = message.content.split(" ")[2] + try: + content = message.content.split(" ")[2] + except IndexError: + content = "" try: arg = message.content.split(" ")[3] except IndexError: From 2de5e16da72917062697a2ff772d05deda80d17a Mon Sep 17 00:00:00 2001 From: Appelsiini1 <37345715+Appelsiini1@users.noreply.github.com> Date: Fri, 16 Apr 2021 23:04:03 +0300 Subject: [PATCH 2/8] Change quote counting - Add time sleep to spread out API requests --- modules/tirsk.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/tirsk.py b/modules/tirsk.py index d416ab3..366cf07 100644 --- a/modules/tirsk.py +++ b/modules/tirsk.py @@ -3,6 +3,7 @@ from modules.common import get_hex_colour from datetime import datetime import re +import time MentionRE = re.compile(r"^.*<@!(\d+)>") @@ -38,6 +39,7 @@ async def tirskCount(message): counter[auth] += 1 else: counter[auth] = 1 + time.sleep(0.07) txt = "" time = datetime.today().strftime("%d.%m.%Y") From 9ab2e8de283ceeb93fecafc81ab5e16a9a68a305 Mon Sep 17 00:00:00 2001 From: Appelsiini1 <37345715+Appelsiini1@users.noreply.github.com> Date: Sat, 17 Apr 2021 01:48:14 +0300 Subject: [PATCH 3/8] Update quote counting - Add spacer to the embed contruction - Fix name conflict --- modules/tirsk.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/tirsk.py b/modules/tirsk.py index 366cf07..6565bad 100644 --- a/modules/tirsk.py +++ b/modules/tirsk.py @@ -1,11 +1,11 @@ import discord import logging +import time from modules.common import get_hex_colour from datetime import datetime import re -import time -MentionRE = re.compile(r"^.*<@!(\d+)>") +MENTION_RE = re.compile(r"^.*<@!(\d+)>") async def tirskCount(message): @@ -16,8 +16,8 @@ async def tirskCount(message): ) msgID = await message.channel.send(embed=emb) counter = {} - async for msg in message.channel.history(limit=None): + time.sleep(0.07) mentions = msg.mentions if len(mentions) == 0: continue @@ -30,7 +30,7 @@ async def tirskCount(message): elif len(mentions) >= 2: # pos = msg.content.rfind("<") # user_id = msg.content[pos:].strip()[3:][:-1] - match = MentionRE.match(msg.content) + match = MENTION_RE.match(msg.content) if match: user_id = match.group(1) user = await message.guild.fetch_member(int(user_id)) @@ -39,18 +39,18 @@ async def tirskCount(message): counter[auth] += 1 else: counter[auth] = 1 - time.sleep(0.07) txt = "" - time = datetime.today().strftime("%d.%m.%Y") + c_time = datetime.today().strftime("%d.%m.%Y") for keypair in sorted(counter.items(), key=lambda x: x[1], reverse=True): name = await message.guild.fetch_member(keypair[0]) + time.sleep(0.07) if name: name = name.display_name else: name = keypair[0] txt += f"{name}: {keypair[1]}\n" - emb.title = f"Quote Scoreboard {time}:" + emb.title = f"Quote Scoreboard {c_time}:" emb.description = txt await msgID.edit(embed=emb) logging.info("Quote counting in {} finished.".format(message.channel.name)) \ No newline at end of file From 11f50e460409c32b419f4c8f160d03fcbf3ff522 Mon Sep 17 00:00:00 2001 From: Appelsiini1 <37345715+Appelsiini1@users.noreply.github.com> Date: Sat, 17 Apr 2021 01:50:40 +0300 Subject: [PATCH 4/8] Progress on nitro adding - Fix for defaults not set when server is anything but TinyCactus' - use now() instead of today() and remove exact time stamp from the time string - Start of nitro addion function --- constants.py | 2 +- modules/nitro.py | 51 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/constants.py b/constants.py index 0553bd8..58ecd5f 100644 --- a/constants.py +++ b/constants.py @@ -21,4 +21,4 @@ def get_tokens(): DISCORD_TOKEN = TOKENS[0].lstrip("TOKEN").strip()[1:] TWIT_API_KEY = TOKENS[1].lstrip("API_KEY").strip()[1:] TWIT_API_SECRET = TOKENS[2].lstrip("API_SECRET").strip()[1:] -VERSION = "v1.11.7" \ No newline at end of file +VERSION = "v1.11.8" \ No newline at end of file diff --git a/modules/nitro.py b/modules/nitro.py index c5b5793..7642a1c 100644 --- a/modules/nitro.py +++ b/modules/nitro.py @@ -1,7 +1,9 @@ +import re import discord import logging import sqlite3 import datetime + from modules.common import get_hex_colour from constants import DB_F @@ -10,6 +12,8 @@ HEART_EMOTE = "\N{SPARKLING HEART}" SURPRISE_EMOTE = "\N{FACE WITH OPEN MOUTH}" +MENTION_RE = re.compile(r"^.*<@!(\d+)>") + def constructEmbed(message, boosts): emb = discord.Embed() @@ -35,6 +39,9 @@ def constructEmbed(message, boosts): ) HeartEmote = HEART_EMOTE SurpriseEmote = SURPRISE_EMOTE + else: + HeartEmote = HEART_EMOTE + SurpriseEmote = SURPRISE_EMOTE if boosts == 1: txt = f"{HeartEmote} {message.guild.name} just got a New Boost by **{message.author.display_name}**! {HeartEmote}" @@ -62,7 +69,7 @@ async def trackNitro(message): c = conn.cursor() guild_id = message.guild.id booster_id = message.author.id - time = datetime.datetime.today().strftime("%d.%m.%Y %H:%M:%S") + time = datetime.datetime.now().strftime("%d.%m.%Y") emb = discord.Embed() try: @@ -72,11 +79,9 @@ async def trackNitro(message): c.execute(f"SELECT * FROM NitroTrack WHERE Guild_ID={guild_id}") track = c.fetchone() - # print(track) if track == None: - print("Here") return - elif track[1] == 2: # TODO Only post a notice of the boost but do not track + elif track[1] == 2: # Only notice, no tracking. emb = constructEmbed(message, boostAmount) try: await message.channel.send(embed=emb) @@ -269,8 +274,44 @@ async def Tracking(message): async def addNitro(message): - pass + # command structure + # !c nitro add [@user or id], [amount], [time ONLY DATE!! as DD.MM.YYYY] + # if time is omitted, use current time + prefix = "!c nitro add " + args = message.content[len(prefix):].split(" ") + + emb = discord.Embed() + + try: + user_raw = args[0] + boosts = int(args[1]) + except Exception: + emb.title = "Invalid user ID or boost amount. Give user as an ID or a mention. Boost amount should be an integer." + emb.color = get_hex_colour(error=True) + await message.channel.send(embed=emb) + return + + match = MENTION_RE.match(user_raw) + if match: + user_id = match.group(1) + user = message.guild.get_member(int(user_id)) + else: + try: + user_id = int(user_raw) + user = message.guild.get_member(user_id) + except Exception: + emb.title = "Invalid user ID or boost amount. Give user as an ID or a mention. Boost amount should be an integer." + emb.color = get_hex_colour(error=True) + await message.channel.send(embed=emb) + return + + try: + time = args[2] + boostTime = datetime.datetime.strptime(time, "%d.%m.%Y") + except Exception: + boostTime = datetime.datetime.today().strftime("%d.%m.%Y") + async def parseNitroAddition(message): pass From 5d26202a28dc4bf30f11a9a62fad4443509b4926 Mon Sep 17 00:00:00 2001 From: Appelsiini1 <37345715+Appelsiini1@users.noreply.github.com> Date: Sat, 17 Apr 2021 03:03:05 +0300 Subject: [PATCH 5/8] Finish adding boosts manually - Move command checking to it's own function - Add help command --- constants.py | 2 +- main.py | 11 +--- modules/nitro.py | 154 +++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 143 insertions(+), 24 deletions(-) diff --git a/constants.py b/constants.py index 58ecd5f..4caf6ed 100644 --- a/constants.py +++ b/constants.py @@ -21,4 +21,4 @@ def get_tokens(): DISCORD_TOKEN = TOKENS[0].lstrip("TOKEN").strip()[1:] TWIT_API_KEY = TOKENS[1].lstrip("API_KEY").strip()[1:] TWIT_API_SECRET = TOKENS[2].lstrip("API_SECRET").strip()[1:] -VERSION = "v1.11.8" \ No newline at end of file +VERSION = "v1.11.9" \ No newline at end of file diff --git a/main.py b/main.py index 855b793..bd72930 100644 --- a/main.py +++ b/main.py @@ -106,19 +106,10 @@ async def on_message(message): await vote.vote(message) elif cmd == "pop": await pop.pop(message) - # elif cmd == "test": - # await nitro.test(message) elif cmd == "mood": await message.channel.send("https://cdn.discordapp.com/attachments/816694548457324544/830847194142605403/hui_saakeli_tata_elamaa.mp4") elif cmd == "nitro": - try: - arg2 = message.content.split(" ")[2] - if arg2.strip() in ["start", "stop", "notice"]: - await nitro.Tracking(message) - else: - await message.channel.send("What was that?") - except IndexError: - await message.channel.send("Unknown argument. Use '!c nitro help' for correct syntax.") + await nitro.nitroJunction(message) else: await message.channel.send("What was that?") diff --git a/modules/nitro.py b/modules/nitro.py index 7642a1c..86ab299 100644 --- a/modules/nitro.py +++ b/modules/nitro.py @@ -18,7 +18,7 @@ def constructEmbed(message, boosts): emb = discord.Embed() - if message.guild.id == 181079344611852288: # TinyCactus easter egg + if message.guild.id == 181079344611852288: # TinyCactus easter egg emote_name = "cheart" emote_name2 = "cacsurp2" succ = 0 @@ -81,7 +81,7 @@ async def trackNitro(message): track = c.fetchone() if track == None: return - elif track[1] == 2: # Only notice, no tracking. + elif track[1] == 2: # Only notice, no tracking. emb = constructEmbed(message, boostAmount) try: await message.channel.send(embed=emb) @@ -278,13 +278,13 @@ async def addNitro(message): # !c nitro add [@user or id], [amount], [time ONLY DATE!! as DD.MM.YYYY] # if time is omitted, use current time prefix = "!c nitro add " - args = message.content[len(prefix):].split(" ") + args = message.content[len(prefix) :].split(" ") emb = discord.Embed() try: user_raw = args[0] - boosts = int(args[1]) + boostAmount = int(args[1]) except Exception: emb.title = "Invalid user ID or boost amount. Give user as an ID or a mention. Boost amount should be an integer." emb.color = get_hex_colour(error=True) @@ -298,24 +298,152 @@ async def addNitro(message): else: try: user_id = int(user_raw) - user = message.guild.get_member(user_id) - except Exception: - emb.title = "Invalid user ID or boost amount. Give user as an ID or a mention. Boost amount should be an integer." + user = await message.guild.fetch_member(user_id) + except Exception: + emb.title = "Invalid user ID, boost amount or user not found. Give user as an ID or a mention. Boost amount should be an integer." emb.color = get_hex_colour(error=True) await message.channel.send(embed=emb) return - + noTime = 0 try: time = args[2] - boostTime = datetime.datetime.strptime(time, "%d.%m.%Y") except Exception: boostTime = datetime.datetime.today().strftime("%d.%m.%Y") + noTime = 1 + try: + boostTime = datetime.datetime.strptime(time, "%d.%m.%Y") + except ValueError: + if noTime == 0: + emb.title = ( + "Invalid timeformat. Please give boost time in the format 'DD.MM.YYYY'." + ) + emb.color = get_hex_colour(error=True) + await message.channel.send(embed=emb) + return + else: + pass - + guild_id = message.guild.id + with sqlite3.connect(DB_F) as conn: + c = conn.cursor() + c.execute( + "SELECT * FROM NitroBoosts WHERE Guild_ID=? AND User_ID=?", + (guild_id, user.id), + ) + previousBoosts = c.fetchone() + if previousBoosts == None: + c.execute("SELECT Boost_ID FROM NitroBoosts ORDER BY Boost_ID DESC") + lastID = c.fetchone() + if lastID == None: + lastID = 1 + else: + lastID = lastID[0] + 1 -async def parseNitroAddition(message): - pass + # Boost_ID INT UNIQUE, + # User_ID INT, + # Guild_ID INT, + # Boost_Time TEXT, + # LatestBoost TEXT, + # Boosts INT, + i = 0 + success = 0 + while i < 10: + try: + c.execute( + "INSERT INTO NitroBoosts VALUES (?,?,?,?,?,?)", + (lastID, user.id, guild_id, boostTime, boostTime, boostAmount), + ) + success = 1 + break + except sqlite3.IntegrityError: + i += 1 + lastID += 1 + if success != 1: + logging.error("Could not add boost to database.") + emb.title = f"There was a database error adding a boost by '{user.display_name}'. Please try again later." + emb.color = get_hex_colour(error=True) + await message.channel.send(embed=emb) + return + emb.description = ( + f"Added {boostAmount} boost(s) by {user.display_name} into database." + ) + emb.color = get_hex_colour(cora_eye=True) + conn.commit() + await message.channel.send(embed=emb) + + else: + c.execute( + "SELECT * FROM NitroBoosts WHERE Guild_ID=? AND User_ID=?", + (guild_id, user.id), + ) + boost = c.fetchone() + boosts = boost[5] + newValue = boosts + boostAmount + # TODO Compare the times of boosts and only update if necessary (either latest or first boost) + c.execute( + "UPDATE NitroBoosts SET Boosts=?, LatestBoost=? WHERE Guild_ID=? AND User_ID=?", + (newValue, time, guild_id, user.id), + ) + emb.description = ( + f"Added {boostAmount} boost(s) by {user.display_name} into database." + ) + emb.color = get_hex_colour(cora_eye=True) + conn.commit() + await message.channel.send(embed=emb) async def delNitro(message): - pass \ No newline at end of file + pass + + +async def nitroHelp(message): + emb = discord.Embed() + emb.title = "Nitro Tracking" + emb.color = get_hex_colour(cora_blonde=True) + txt = "**General info**\n\ + This is the best implementation of nitro tracking that is possible within Discord limitations.\n\ + It can track boost amount, times, and boosters. HOWEVER, it cannot continuously check if the boosts are valid. Checks are made either \n\ + automatically when '!c nitro spin' command is used or when using '!c nitro check' manually. These commands however can only see overall Nitro status of the user.\n\ + It cannot see wheter individual boosts have expired, only if all of them have. Please see these commands below for more info.\n\ + **NOTE!!** All commands below require administrator priviledges.\n\ + \n**Enabling/Disabling nitro tracking on server**\n\ + To enable nitro tracking on your server, use\n\ + ```!c nitro start```\n\ + To ONLY show boost announcements but not track boosts, use\n\ + ```!c nitro notice```\n\ + To stop tracking or announcements, use\n\ + ```!c nitro stop```\n\n\ + **Adding boosts manually**\n\ + If you have older boosts active on the server, or an error occured during tracking, you can add them manually to the bot's database by using\n\ + ```!c nitro add [user], [amount], [date]```\n\ + _Arguments:_\n\ + _user_: Spesifies who the booster is. This can be a mention (@user) or a user ID as an integer.\n\ + _amount_: The amount of boosts to add as an integer.\n\ + _date_: The date of the boost(s). This argument is optional. If it is not given, current date will be used.\n\ + \tIf the user is not in the database, this will be added to both the latest and first boost dates. Otherwise the date is compared to the dates\n\ + already in the database and figure out which one to update.\n\ + " + await message.channel.send(embed=emb) + + +async def nitroJunction(message): + if message.author.guild_permissions.administrator: + try: + arg2 = message.content.split(" ")[2] + if arg2.strip() in ["start", "stop", "notice"]: + await Tracking(message) + elif arg2.strip() == "add": + await addNitro(message) + else: + await message.channel.send( + "Unknown argument. Use '!c nitro help' for correct syntax." + ) + except IndexError: + await message.channel.send( + "No arguments given. Use '!c nitro help' for correct syntax." + ) + else: + emb = discord.Embed() + emb.description = "You do not have the permissions to use this." + emb.color = get_hex_colour(error=True) + await message.channel.send(embed=emb) \ No newline at end of file From 721527174a0299e7cbce34682021d1decaeafcd6 Mon Sep 17 00:00:00 2001 From: Appelsiini1 <37345715+Appelsiini1@users.noreply.github.com> Date: Sat, 17 Apr 2021 03:03:30 +0300 Subject: [PATCH 6/8] Code formatting in poll --- modules/poll.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/poll.py b/modules/poll.py index 57bed7a..ca112a5 100644 --- a/modules/poll.py +++ b/modules/poll.py @@ -9,6 +9,8 @@ from constants import DB_F _POLL_PREFIX = "!c poll " + +# only affects rolepolls MAX_OPTIONS = 20 RoleRE1 = re.compile(r"^.*<@&(\d+)>") @@ -197,7 +199,9 @@ async def startBasicPoll(message): try: await message.delete() except discord.errors.NotFound: - logging.exception("Could not delete message when creating a basic poll. Message was not found.") + logging.exception( + "Could not delete message when creating a basic poll. Message was not found." + ) else: emb.description = "Exceeded maximum option amount of 20 options for polls!" emb.color = get_hex_colour(error=True) @@ -604,7 +608,7 @@ async def startRolePoll(message): elif len(args) <= MAX_OPTIONS: poll_txt = "Use '!c vote' -command to vote in this poll! See below the poll for an example.\n\n**Options:**\n" option_str = "" - + i = 1 for o in args: option = o.strip().lstrip("[").rstrip("]") @@ -613,7 +617,7 @@ async def startRolePoll(message): option_str += option + ";" poll_txt += f"**{str(i)}**: {option}\n" i += 1 - numberOfOptions = i-1 + numberOfOptions = i - 1 if len(poll_txt) >= 2048: emb.description = ( @@ -680,7 +684,7 @@ async def startRolePoll(message): option2 = random.randint(1, numberOfOptions) if option2 == option1 and option2 != numberOfOptions: option2 += 1 - elif option2 == option1 and option1-1 != 0: + elif option2 == option1 and option1 - 1 != 0: option2 -= 1 else: option1 = 1 From f80203c0539cfe1e71c4f76603cfcbd7110ea874 Mon Sep 17 00:00:00 2001 From: Appelsiini1 <37345715+Appelsiini1@users.noreply.github.com> Date: Mon, 19 Apr 2021 02:37:00 +0300 Subject: [PATCH 7/8] Nitro boost delete + small tweaks - Add nitro boost delete command - Add nitro commands to command help - Add nitro boosts delete to nitro help - Remove unnecessary console print - Update choose command's entry in command help to be clearer against other commands - Update version number --- constants.py | 2 +- main.py | 1 - modules/commands.py | 3 +- modules/nitro.py | 94 +++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 94 insertions(+), 6 deletions(-) diff --git a/constants.py b/constants.py index 4caf6ed..b1393d7 100644 --- a/constants.py +++ b/constants.py @@ -21,4 +21,4 @@ def get_tokens(): DISCORD_TOKEN = TOKENS[0].lstrip("TOKEN").strip()[1:] TWIT_API_KEY = TOKENS[1].lstrip("API_KEY").strip()[1:] TWIT_API_SECRET = TOKENS[2].lstrip("API_SECRET").strip()[1:] -VERSION = "v1.11.9" \ No newline at end of file +VERSION = "v1.11.10" \ No newline at end of file diff --git a/main.py b/main.py index bd72930..edcaef7 100644 --- a/main.py +++ b/main.py @@ -55,7 +55,6 @@ async def on_message(message): message.content.find("sairasta") != -1 or message.content.find("ei oo normaalii") != -1 ): - print("sairasta") msg = "https://cdn.discordapp.com/attachments/693166291468681227/823282434203189258/eioonormaalii.gif" await message.channel.send(msg) return diff --git a/modules/commands.py b/modules/commands.py index 3465896..fcc27b9 100644 --- a/modules/commands.py +++ b/modules/commands.py @@ -11,7 +11,7 @@ async def cmds(message): inspire insult [user] f (alias: F) -choose [option1 | option2 | ...] +choose option1 | option2 | ... vacc [Area code (or empty for all areas) | help] poll [new|end|help] vote help @@ -23,6 +23,7 @@ async def cmds(message): poll [set|del]roles poll roles poll new -r +nitro [add|del|start|stop|notice] """ emb = discord.Embed( title="List of available commands:", diff --git a/modules/nitro.py b/modules/nitro.py index 86ab299..ca33723 100644 --- a/modules/nitro.py +++ b/modules/nitro.py @@ -393,7 +393,91 @@ async def addNitro(message): async def delNitro(message): - pass + # Command structure + # !c nitro del @person (amount / 'all') + + prefix = "!c nitro del " + args = message.content[len(prefix) :].split(" ") + + emb = discord.Embed() + + try: + user_raw = args[0] + boostAmount = int(args[1]) + except IndexError: + emb.title = "Invalid user ID or boost amount. Give user as an ID or a mention. Boost amount should be an integer." + emb.color = get_hex_colour(error=True) + await message.channel.send(embed=emb) + return + except ValueError: + if args[1].strip().lower() == "all": + boostAmount = 99999 + else: + emb.title = "Invalid user ID or boost amount. Give user as an ID or a mention. Boost amount should be an integer." + emb.color = get_hex_colour(error=True) + await message.channel.send(embed=emb) + return + + match = MENTION_RE.match(user_raw) + if match: + user_id = match.group(1) + user = message.guild.get_member(int(user_id)) + else: + try: + user_id = int(user_raw) + user = await message.guild.fetch_member(user_id) + except Exception: + emb.title = "Invalid user ID or user not found. Give user as an ID or a mention. Boost amount should be an integer." + emb.color = get_hex_colour(error=True) + await message.channel.send(embed=emb) + return + + guild_id = message.guild.id + with sqlite3.connect(DB_F) as conn: + c = conn.cursor() + c.execute( + "SELECT * FROM NitroBoosts WHERE Guild_ID=? AND User_ID=?", + (guild_id, user.id), + ) + previousBoosts = c.fetchone() + if previousBoosts == None: + emb.title = "User has no boosts on record to delete." + emb.color = get_hex_colour(error=True) + await message.channel.send(emebed=emb) + return + else: + c.execute( + "SELECT * FROM NitroBoosts WHERE Guild_ID=? AND User_ID=?", + (guild_id, user.id), + ) + boost = c.fetchone() + boosts = boost[5] + newValue = boosts - boostAmount + try: + if boostAmount == 99999 or newValue <= 0: + c.execute( + "DELETE FROM NitroBoosts WHERE Guild_ID=? AND User_ID=?", + (guild_id, user.id), + ) + emb.description = f"Deleted all ({boosts}) boosts by {user.display_name} from the database." + + else: + c.execute( + "UPDATE NitroBoosts SET Boosts=? WHERE Guild_ID=? AND User_ID=?", + (newValue, guild_id, user.id), + ) + emb.description = f"Deleted {boostAmount} boost(s) by {user.display_name} from the database." + + except Exception: + logging.exception("Error updating database in 'nitro del' command.") + emb.title = "Something went wrong updating database. Please try again." + emb.color = get_hex_colour(error=True) + await message.channel.send(embed=emb) + return + + emb.color = get_hex_colour(cora_eye=True) + conn.commit() + await message.channel.send(embed=emb) async def nitroHelp(message): @@ -421,8 +505,12 @@ async def nitroHelp(message): _amount_: The amount of boosts to add as an integer.\n\ _date_: The date of the boost(s). This argument is optional. If it is not given, current date will be used.\n\ \tIf the user is not in the database, this will be added to both the latest and first boost dates. Otherwise the date is compared to the dates\n\ - already in the database and figure out which one to update.\n\ - " + \talready in the database and figure out which one to update.\n\ + \n**Deleting boosts from database**\n\ + The bot will delete expired boosts from database automatically if '!c nitro spin' command is issued. However, if you wish to delete boost(s) manually,\n\ + you can use this command:\n\ + ```!c nitro del [@user or user ID] [amount or 'all']```" + emb.description = txt await message.channel.send(embed=emb) From 01c22a45235acc91ba2cabf5edd8c8ae1028a233 Mon Sep 17 00:00:00 2001 From: Appelsiini1 <37345715+Appelsiini1@users.noreply.github.com> Date: Tue, 20 Apr 2021 02:09:48 +0300 Subject: [PATCH 8/8] Code cleanup, bug fixes and boost time comparison - Bump version number - Change i -variables to use enumerate function where possible - Changed some while loops to for loops - Simplified & cleaned some if statements - Change vote example to have minimum of 2 votes on the first option - Add boost time comparison to manual nitro add - Fixed dumb code in boost time creation in manual nitro add - Spesified error message in boost announcement sending - Add error handling for other errors in boost announcement sending - Add vote command to command help --- constants.py | 6 +-- modules/commands.py | 1 + modules/nitro.py | 95 ++++++++++++++++++++++++++------------------- modules/poll.py | 55 +++++++++----------------- modules/vote.py | 12 ++---- 5 files changed, 82 insertions(+), 87 deletions(-) diff --git a/constants.py b/constants.py index b1393d7..36339e7 100644 --- a/constants.py +++ b/constants.py @@ -1,5 +1,5 @@ import os -from logging import exception +import logging from sys import exit @@ -9,7 +9,7 @@ def get_tokens(): with open(".env", "r") as f: tokens = f.readlines() except Exception: - exception("Could not acquire environment variables. Stopping.") + logging.exception("Could not acquire environment variables. Stopping.") exit(1) return tokens @@ -21,4 +21,4 @@ def get_tokens(): DISCORD_TOKEN = TOKENS[0].lstrip("TOKEN").strip()[1:] TWIT_API_KEY = TOKENS[1].lstrip("API_KEY").strip()[1:] TWIT_API_SECRET = TOKENS[2].lstrip("API_SECRET").strip()[1:] -VERSION = "v1.11.10" \ No newline at end of file +VERSION = "v1.11.11" \ No newline at end of file diff --git a/modules/commands.py b/modules/commands.py index fcc27b9..f91f7b2 100644 --- a/modules/commands.py +++ b/modules/commands.py @@ -15,6 +15,7 @@ async def cmds(message): vacc [Area code (or empty for all areas) | help] poll [new|end|help] vote help +vote [Poll ID] [option:votes], [option:votes], ... pop [number between 1-14] Admin commands: diff --git a/modules/nitro.py b/modules/nitro.py index ca33723..5ab4cc1 100644 --- a/modules/nitro.py +++ b/modules/nitro.py @@ -106,10 +106,8 @@ async def trackNitro(message): if previousBoosts == None: c.execute("SELECT Boost_ID FROM NitroBoosts ORDER BY Boost_ID DESC") lastID = c.fetchone() - if lastID == None: - lastID = 1 - else: - lastID = lastID[0] + 1 + newID = 0 + newID += 1 if lastID != None else 1 # Boost_ID INT UNIQUE, # User_ID INT, @@ -117,19 +115,18 @@ async def trackNitro(message): # Boost_Time TEXT, # LatestBoost TEXT, # Boosts INT, - i = 0 success = 0 - while i < 10: + for i in range(10): try: c.execute( "INSERT INTO NitroBoosts VALUES (?,?,?,?,?,?)", - (lastID, booster_id, guild_id, time, time, boostAmount), + (newID, booster_id, guild_id, time, time, boostAmount), ) success = 1 break except sqlite3.IntegrityError: - i += 1 - lastID += 1 + newID += 1 + if success != 1: logging.error("Could not add boost to database.") dm_channel = message.guild.owner.dm_channel @@ -169,12 +166,23 @@ async def trackNitro(message): ) emb = constructEmbed(message, boostAmount) try: - await message.channel.send(embed=emb) conn.commit() + await message.channel.send(embed=emb) except discord.errors.Forbidden: logging.error("Unable to send message due to 403 - Forbidden") emb.clear_fields() - emb.description = f"Unable to send boost announcement to system message channel in '{message.guild.name}'. Please make sure I have the proper rights to post messages to that channel." + emb.description = f"Unable to send boost announcement to system message channel in '{message.guild.name}'. Please make sure I have the proper rights to post messages to that channel.\n\ + The boost was succesfully recorded to database though." + emb.color = get_hex_colour(error=True) + dm_channel = message.guild.owner.dm_channel + if dm_channel == None: + dm_channel = await message.guild.owner.create_dm() + await dm_channel.send(embed=emb) + return + except Exception: + logging.exception("Something went wrong committing database changes.") + emb.clear_fields() + emb.description = f"Something went wrong when trying to add latest boost in {message.guild.name} to the database. Please add it manually." emb.color = get_hex_colour(error=True) dm_channel = message.guild.owner.dm_channel if dm_channel == None: @@ -308,20 +316,18 @@ async def addNitro(message): try: time = args[2] except Exception: - boostTime = datetime.datetime.today().strftime("%d.%m.%Y") + boostTime = datetime.datetime.today() noTime = 1 - try: - boostTime = datetime.datetime.strptime(time, "%d.%m.%Y") - except ValueError: - if noTime == 0: + if noTime == 0: + try: + boostTime = datetime.datetime.strptime(time, "%d.%m.%Y") + except ValueError: emb.title = ( "Invalid timeformat. Please give boost time in the format 'DD.MM.YYYY'." ) emb.color = get_hex_colour(error=True) await message.channel.send(embed=emb) return - else: - pass guild_id = message.guild.id with sqlite3.connect(DB_F) as conn: @@ -334,30 +340,34 @@ async def addNitro(message): if previousBoosts == None: c.execute("SELECT Boost_ID FROM NitroBoosts ORDER BY Boost_ID DESC") lastID = c.fetchone() - if lastID == None: - lastID = 1 - else: - lastID = lastID[0] + 1 - - # Boost_ID INT UNIQUE, - # User_ID INT, - # Guild_ID INT, - # Boost_Time TEXT, - # LatestBoost TEXT, - # Boosts INT, - i = 0 + newID = 0 + newID = 1 if lastID != None else 1 + + # Boost_ID INT UNIQUE, 0 + # User_ID INT, 1 + # Guild_ID INT, 2 + # Boost_Time TEXT, 3 + # LatestBoost TEXT, 4 + # Boosts INT, 5 success = 0 - while i < 10: + for i in range(10): try: c.execute( "INSERT INTO NitroBoosts VALUES (?,?,?,?,?,?)", - (lastID, user.id, guild_id, boostTime, boostTime, boostAmount), + ( + newID, + user.id, + guild_id, + boostTime.strftime("%d.%m.%Y"), + boostTime.strftime("%d.%m.%Y"), + boostAmount, + ), ) success = 1 break except sqlite3.IntegrityError: - i += 1 - lastID += 1 + newID += 1 + if success != 1: logging.error("Could not add boost to database.") emb.title = f"There was a database error adding a boost by '{user.display_name}'. Please try again later." @@ -378,12 +388,19 @@ async def addNitro(message): ) boost = c.fetchone() boosts = boost[5] + oldBoostTime = datetime.datetime.strptime(boost[4], "%d.%m.%Y") newValue = boosts + boostAmount - # TODO Compare the times of boosts and only update if necessary (either latest or first boost) - c.execute( - "UPDATE NitroBoosts SET Boosts=?, LatestBoost=? WHERE Guild_ID=? AND User_ID=?", - (newValue, time, guild_id, user.id), - ) + if boostTime < oldBoostTime: + if boostTime < oldBoostTime: + c.execute( + "UPDATE NitroBoosts SET Boosts=?, Boost_Time=? WHERE Guild_ID=? AND User_ID=?", + (newValue, boostTime.strftime("%d.%m.%Y"), guild_id, user.id), + ) + else: + c.execute( + "UPDATE NitroBoosts SET Boosts=?, LatestBoost=? WHERE Guild_ID=? AND User_ID=?", + (newValue, boostTime.strftime("%d.%m.%Y"), guild_id, user.id), + ) emb.description = ( f"Added {boostAmount} boost(s) by {user.display_name} into database." ) diff --git a/modules/poll.py b/modules/poll.py index ca112a5..8c6e683 100644 --- a/modules/poll.py +++ b/modules/poll.py @@ -141,11 +141,9 @@ async def startBasicPoll(message): elif len(args) <= 20: poll_txt = "React with the emojis listed below to vote on this poll!\n\n**Options:**\n" emoji_list = selectReactionEmoji(len(args), indexes=True) - i = 0 - for option in args: + for i, option in enumerate(args): emoji = _EMOJIS[emoji_list[i]] poll_txt += emoji + ": " + option.strip() + "\n" - i += 1 if len(poll_txt) >= 2048: emb.description = ( @@ -237,13 +235,13 @@ async def BasicPollEndHelper(poll, message): emb.title = f"Results for '{pollName}'" txt = "" - i = 0 - for keypair in sorted(results.items(), key=lambda x: x[1], reverse=True): + for i, keypair in enumerate( + sorted(results.items(), key=lambda x: x[1], reverse=True) + ): if i == 0: txt += f"{keypair[0]}** : _{keypair[1]-1}_**\n" else: txt += f"{keypair[0]} : {keypair[1]-1}\n" - i += 1 emb.description = txt return emb @@ -528,15 +526,14 @@ async def delRoles(message): await message.channel.send(embed=emb) return - i = 0 with sqlite3.connect(DB_F) as conn: c = conn.cursor() if args[0].strip().lstrip("[").rstrip("]") == "all": c.execute(f"DELETE FROM RolesMaxVotes WHERE Guild_ID={message.guild.id}") - i = -1 + amount = -1 else: - for arg in args: + for i, arg in enumerate(args): match = RoleRE1.match(arg) if match: role_id = match.group(1).strip() @@ -554,10 +551,10 @@ async def delRoles(message): "DELETE FROM RolesMaxVotes WHERE Role_ID=? AND Guild_ID=?", (role_int, message.guild.id), ) - i += 1 + amount = 1 conn.commit() - if i == -1: - i = "all" + if amount == -1: + amount = "all" emb.description = f"Deleted {i} roles from database." emb.color = get_hex_colour(cora_eye=True) await message.channel.send(embed=emb) @@ -594,11 +591,7 @@ async def startRolePoll(message): c.execute("SELECT Poll_ID FROM RolePolls ORDER BY Poll_ID DESC") prevPollID = c.fetchone() - - if prevPollID == None: - poll_id = 100 - else: - poll_id = prevPollID[0] + 1 + poll_id = 100 if prevPollID == None else prevPollID[0] + 1 if len(args) <= 1 or message.content.find(";") == -1: # help command @@ -609,14 +602,12 @@ async def startRolePoll(message): poll_txt = "Use '!c vote' -command to vote in this poll! See below the poll for an example.\n\n**Options:**\n" option_str = "" - i = 1 - for o in args: + for i, o in enumerate(args, start=1): option = o.strip().lstrip("[").rstrip("]") if option == "": continue option_str += option + ";" poll_txt += f"**{str(i)}**: {option}\n" - i += 1 numberOfOptions = i - 1 if len(poll_txt) >= 2048: @@ -640,9 +631,8 @@ async def startRolePoll(message): if titleStatus == 1: title = None - i = 0 success = 0 - while i < 5: + for i in range(5): try: c.execute( "INSERT INTO RolePolls VALUES (?,?,?,?,?,?)", @@ -659,9 +649,8 @@ async def startRolePoll(message): break except sqlite3.IntegrityError: poll_id += 1 - i += 1 emb.set_footer(text=f"Poll ID: {poll_id}") - continue + if success != 1: emb2.title = ( "Poll creation failed due to a database error. Please try again." @@ -694,7 +683,7 @@ async def startRolePoll(message): {1} and {2} vote(s) to option number {3} in this poll.\ ```!c vote {4} {1}:{0}, {3}:{2}```\ \nFor more help, use '!c vote help'".format( - random.randint(1, 5), + random.randint(2, 5), option1, random.randint(1, 5), option2, @@ -742,16 +731,12 @@ async def rolePollEndHelper(message, c, poll=None, polls=None): vote_sums.append(0) for vote in votes: vote_str = vote[3][:-1].split(";") - i = 0 - for option in vote_str: + for i, option in enumerate(vote_str): vote_sums[i] += int(option) - i += 1 - i = 0 txt = "" - for option in vote_sums: + for i, option in enumerate(vote_sums): txt += f"**{poll_options[i]}**: {option}\n" - i += 1 poll_ids.append(poll_id) emb.description = txt emb.title = f"Results for '{poll_name}'" @@ -779,16 +764,12 @@ async def rolePollEndHelper(message, c, poll=None, polls=None): vote_sums.append(0) for vote in votes: vote_str = vote[3][:-1].split(";") - i = 0 - for option in vote_str: + for i, option in enumerate(vote_str): vote_sums[i] += int(option) - i += 1 - i = 0 txt = "" - for option in vote_sums: + for i, option in enumerate(vote_sums): txt += f"**{poll_options[i]}**: {option}\n" - i += 1 poll_ids.append(poll_id) emb.description = txt emb.title = f"Results for '{poll_name}'" diff --git a/modules/vote.py b/modules/vote.py index 8fb4b9e..f490157 100644 --- a/modules/vote.py +++ b/modules/vote.py @@ -137,11 +137,9 @@ async def vote(message): remainingVotes = maxvoteint - totalVotes c.execute("SELECT Vote_ID FROM RolePolls_Votes ORDER BY Vote_ID DESC") - maxid = c.fetchone() - if maxid == None: - maxid = 1 - else: - maxid = maxid[0] + db_id = c.fetchone() + maxid = 1 if db_id == None else db_id[0] + i = 0 success = 0 while i < 5: @@ -167,10 +165,8 @@ async def vote(message): conn.commit() pollOptions = poll[0][4][:-1].split(";") txt = "" - i = 0 - for v in votes: + for i, v in enumerate(votes): txt += f"**{pollOptions[i]}**: {v}\n" - i += 1 emb.description = txt emb.title = f"Your votes for '{poll[0][5]}' were:" emb.set_footer(