From 4f051a8874f6c29e8d372875cfa91ab3058a2db0 Mon Sep 17 00:00:00 2001 From: quentin Date: Sat, 24 Apr 2021 16:11:16 -0500 Subject: [PATCH] cleaned up imports --- .idea/Discord Bot.iml | 3 +- .idea/misc.xml | 2 +- .../shelved.patch | 91 ------------------- ...3_27_2021_4_05_PM__Default_Changelist_.xml | 4 - scr/Modules/TMC/McRoll.py | 1 - 5 files changed, 3 insertions(+), 98 deletions(-) delete mode 100644 .idea/shelf/Uncommitted_changes_before_Update_at_3_27_2021_4_05_PM_[Default_Changelist]/shelved.patch delete mode 100644 .idea/shelf/Uncommitted_changes_before_Update_at_3_27_2021_4_05_PM__Default_Changelist_.xml diff --git a/.idea/Discord Bot.iml b/.idea/Discord Bot.iml index 7370ee6..e187969 100644 --- a/.idea/Discord Bot.iml +++ b/.idea/Discord Bot.iml @@ -4,8 +4,9 @@ + - + diff --git a/.idea/misc.xml b/.idea/misc.xml index f642e6e..5544afd 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/.idea/shelf/Uncommitted_changes_before_Update_at_3_27_2021_4_05_PM_[Default_Changelist]/shelved.patch b/.idea/shelf/Uncommitted_changes_before_Update_at_3_27_2021_4_05_PM_[Default_Changelist]/shelved.patch deleted file mode 100644 index f645abb..0000000 --- a/.idea/shelf/Uncommitted_changes_before_Update_at_3_27_2021_4_05_PM_[Default_Changelist]/shelved.patch +++ /dev/null @@ -1,91 +0,0 @@ -Index: scr/Modules/TMC/McRoll.py -IDEA additional info: -Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP -<+>import collections\r\nfrom typing import Union\r\nimport discord\r\nfrom discord.ext import commands\r\nimport math\r\nfrom datetime import datetime, timedelta\r\nimport pymysql\r\nfrom apscheduler.schedulers.asyncio import AsyncIOScheduler\r\n\r\npassword = open(\"../sqlPass.txt\", 'r').read()\r\n\r\nscheduler = AsyncIOScheduler({\r\n 'apscheduler.jobstores.default': {\r\n 'type': 'sqlalchemy',\r\n 'url': f'mysql+pymysql://Quentin:{password}@192.168.1.52:5618/discord_bot?charset=utf8mb4',\r\n },\r\n 'apscheduler.job_defaults.coalesce': 'True',\r\n 'apscheduler.timezone': 'America/Chicago'\r\n})\r\n\r\nscheduler.start()\r\n\r\nmcSelf = None\r\n\r\n\r\ndef get_con() -> pymysql.Connection:\r\n return pymysql.connect(host='192.168.1.52',\r\n port=5618,\r\n user='Quentin',\r\n password=f'{password}',\r\n db='mc',\r\n charset='utf8mb4',\r\n cursorclass=pymysql.cursors.DictCursor)\r\n\r\n\r\nasync def get_poll_results(choices: dict, pollMessageId: int, channelId: int):\r\n print(\"run\")\r\n\r\n getPollResultsReactions = (await McRoll.get_message(mcSelf, pollMessageId, channelId)).reactions\r\n for reaction in getPollResultsReactions:\r\n async for user in reaction.users():\r\n serverIP = reaction_to_serverip(reaction)\r\n if not user.bot:\r\n choices[serverIP]['votes'] = choices[serverIP]['votes'] + 1\r\n\r\n choices[serverIP]['score'] = choices[serverIP]['votes'] * round(\r\n 2 * math.log10(choices[serverIP]['lastActivated'] + 1) + 1, 2)\r\n prune_results(choices)\r\n if len(choices) >= 3:\r\n await McRoll.main_poll_recursion(mcSelf, choices, channelId)\r\n else:\r\n await McRoll.declare_winner(mcSelf, choices, channelId)\r\n\r\n\r\ndef reaction_to_serverip(reaction: Union[discord.Reaction, str]) -> int:\r\n con = get_con()\r\n reaction = str(reaction.emoji.id) \\\r\n if isinstance(reaction.emoji, discord.Emoji) else reaction.emoji.encode('unicode_escape').decode('utf-8')\r\n\r\n with con.cursor() as cursor:\r\n cursor.execute(\"SELECT serverIP FROM mc.server_list WHERE reaction=%s;\", reaction)\r\n serverIp = cursor.fetchone()\r\n con.close()\r\n return serverIp['serverIP']\r\n\r\n\r\ndef get_choices() -> dict:\r\n con = get_con()\r\n choices = {}\r\n with con.cursor() as cursor:\r\n cursor.execute(\"SELECT serverIP, serverName, lastActivated, reaction, getEmoji, onlyServer \"\r\n \"FROM mc.server_list WHERE lastActivated is not null\")\r\n row = cursor.fetchone()\r\n while row is not None:\r\n row['votes'] = 0\r\n row['score'] = 0\r\n choices[row['serverIP']] = row\r\n row = cursor.fetchone()\r\n con.close()\r\n return choices\r\n\r\n\r\ndef pop_lowest(choices: dict):\r\n lowest = {'score': 10}\r\n pop = False\r\n for choice in list(choices):\r\n if choices[choice]['score'] < lowest['score']:\r\n lowest = choices[choice]\r\n pop = True\r\n if pop:\r\n choices.pop(lowest['serverIP'])\r\n\r\n\r\ndef prune_results(choices: dict):\r\n for serverIp, choice in list(choices.items()):\r\n if choice['votes'] <= 0:\r\n del choices[serverIp]\r\n if len(choices) >= 4:\r\n pop_lowest(choices)\r\n pop_lowest(choices)\r\n elif len(choices) == 3:\r\n pop_lowest(choices)\r\n\r\n\r\nclass McRoll(commands.Cog):\r\n def __init__(self, client):\r\n self.client = client\r\n self.embedInfo = \"\"\"Each server has a multiplier based on how long it has been sense that server has been \r\n rolled. When this poll is over all servers with 0 votes will be disregarded. If there are 4 or more servers \r\n left the two with the lowest votes will be disregarded. Poll is rerun until there are only 2 servers, \r\n these two are the winners. Ties reroll the poll. You can only vote for one server per poll. \"\"\"\r\n self.pollMessageId = None\r\n global mcSelf\r\n mcSelf = self # This is a bad way of doing things but it works\r\n\r\n @commands.command()\r\n async def mc_roll(self, ctx):\r\n if ctx.message.author.id != 305589587215122432:\r\n return\r\n choices = get_choices()\r\n await self.main_poll_recursion(choices, ctx.channel.id)\r\n\r\n async def main_poll_recursion(self, choices, channelId):\r\n self.pollMessageId = (await self.poll(choices, channelId)).id\r\n scheduler.add_job(get_poll_results, 'date',\r\n run_date=(datetime.now() + timedelta(days=1)),\r\n args=[choices, self.pollMessageId, channelId],\r\n coalesce=True)\r\n\r\n @commands.Cog.listener()\r\n async def on_reaction_add(self, reaction, user):\r\n if self.pollMessageId is None:\r\n return\r\n reactedUsers = {}\r\n if reaction.message.id == self.pollMessageId and user.id != 533427166193385494:\r\n for iReaction in reaction.message.reactions:\r\n async for iUser in iReaction.users():\r\n if iUser.id != 533427166193385494:\r\n if iUser.id not in reactedUsers:\r\n reactedUsers[iUser.id] = False\r\n if reactedUsers[iUser.id]:\r\n await reaction.remove(user)\r\n self.pollMessageId = reaction.message.id\r\n await user.send(\r\n \"You can only vote for one option, please remove your previous vote to change it.\")\r\n return\r\n self.pollMessageId = reaction.message.id\r\n reactedUsers[iUser.id] = True\r\n\r\n async def poll(self, choices: dict, channel: int) -> discord.Message:\r\n channel = await self.client.fetch_channel(channel)\r\n embed = discord.Embed(title=\"Poll\", description=self.embedInfo,\r\n timestamp=(datetime.utcnow() + timedelta(days=1)))\r\n for choice in choices.values():\r\n embed.add_field(\r\n name=choice['serverName'] + ' ' + str(self.client.get_emoji(int(choice['reaction'])))\r\n if choice['getEmoji']\r\n else bytes(choice['reaction'], \"utf-8\").decode(\"unicode_escape\"),\r\n value=\"Multiplier : \" + str(round(2 * math.log10(choice['lastActivated'] + 1) + 1, 2)) + '\\n' + \"Last Rolled : \" + str(choice['lastActivated'] * 2) + \" weeks ago.\") + \"\\nThis is an only server, meaning if it wins it will be the only winner\" if choice['onlyServer'] else \"\"\r\n\r\n pollMessage = await channel.send(embed=embed)\r\n await channel.send('@everyone')\r\n\r\n for choice in choices.values():\r\n await pollMessage.add_reaction(self.client.get_emoji(int(choice['reaction']))\r\n if choice['getEmoji']\r\n else bytes(choice['reaction'], \"utf-8\").decode(\"unicode_escape\"))\r\n return pollMessage\r\n\r\n async def declare_winner(self, choices, channelId):\r\n embed = discord.Embed(title=\"Winner\", description=\"Congratulations\")\r\n for item in list(choices):\r\n winner = choices[item]\r\n embed.add_field(\r\n name=winner['serverName'],\r\n value=\"Multiplier : \" + str(round(2 * math.log10(winner['lastActivated'] + 1) + 1, 2)) + '\\n' +\r\n \"Last Rolled : \" + str(winner['lastActivated'] * 2) + \" weeks ago.\" + '\\n' +\r\n \"Votes : \" + str(winner['votes']) + '\\n' +\r\n \"Calculated Votes: \" + str(\r\n winner['votes'] * round(2 * math.log10(winner['lastActivated'] + 1) + 1, 2))\r\n )\r\n channel = await self.client.fetch_channel(channelId)\r\n await channel.send(embed=embed)\r\n await channel.send(\"@everyone\")\r\n\r\n async def get_message(self, messageId, channelId):\r\n channel = await self.client.fetch_channel(channelId)\r\n return await channel.fetch_message(messageId)\r\n\r\n\r\ndef setup(client):\r\n client.add_cog(McRoll(client))\r\n -Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP -<+>UTF-8 -=================================================================== -diff --git a/scr/Modules/TMC/McRoll.py b/scr/Modules/TMC/McRoll.py ---- a/scr/Modules/TMC/McRoll.py (revision 9e407d37bc10832d7e9a5f106233446c700253a9) -+++ b/scr/Modules/TMC/McRoll.py (date 1616878641418) -@@ -1,4 +1,3 @@ --import collections - from typing import Union - import discord - from discord.ext import commands -@@ -12,7 +11,7 @@ - scheduler = AsyncIOScheduler({ - 'apscheduler.jobstores.default': { - 'type': 'sqlalchemy', -- 'url': f'mysql+pymysql://Quentin:{password}@192.168.1.52:5618/discord_bot?charset=utf8mb4', -+ 'url': f'mysql+pymysql://quentin:{password}@192.168.1.52:5618/discord_bot?charset=utf8mb4', - }, - 'apscheduler.job_defaults.coalesce': 'True', - 'apscheduler.timezone': 'America/Chicago' -@@ -26,9 +25,9 @@ - def get_con() -> pymysql.Connection: - return pymysql.connect(host='192.168.1.52', - port=5618, -- user='Quentin', -+ user='quentin', - password=f'{password}', -- db='mc', -+ db='minecraft', - charset='utf8mb4', - cursorclass=pymysql.cursors.DictCursor) - -@@ -58,7 +57,7 @@ - if isinstance(reaction.emoji, discord.Emoji) else reaction.emoji.encode('unicode_escape').decode('utf-8') - - with con.cursor() as cursor: -- cursor.execute("SELECT serverIP FROM mc.server_list WHERE reaction=%s;", reaction) -+ cursor.execute("SELECT serverIP FROM minecraft.server_list WHERE reaction=%s;", reaction) - serverIp = cursor.fetchone() - con.close() - return serverIp['serverIP'] -@@ -69,7 +68,7 @@ - choices = {} - with con.cursor() as cursor: - cursor.execute("SELECT serverIP, serverName, lastActivated, reaction, getEmoji, onlyServer " -- "FROM mc.server_list WHERE lastActivated is not null") -+ "FROM minecraft.server_list WHERE lastActivated is not null") - row = cursor.fetchone() - while row is not None: - row['votes'] = 0 -@@ -153,10 +152,14 @@ - timestamp=(datetime.utcnow() + timedelta(days=1))) - for choice in choices.values(): - embed.add_field( -- name=choice['serverName'] + ' ' + str(self.client.get_emoji(int(choice['reaction']))) -- if choice['getEmoji'] -- else bytes(choice['reaction'], "utf-8").decode("unicode_escape"), -- value="Multiplier : " + str(round(2 * math.log10(choice['lastActivated'] + 1) + 1, 2)) + '\n' + "Last Rolled : " + str(choice['lastActivated'] * 2) + " weeks ago.") + "\nThis is an only server, meaning if it wins it will be the only winner" if choice['onlyServer'] else "" -+ name=choice['serverName'] + ' ' + (str(self.client.get_emoji(int(choice['reaction']))) -+ if choice['getEmoji'] -+ else bytes(choice['reaction'], "utf-8").decode("unicode_escape")), -+ value="Multiplier : " + str( -+ round(2 * math.log10(choice['lastActivated'] + 1) + 1, 2)) + '\n' + "Last Rolled : " + -+ str(choice['lastActivated'] * 2) + " weeks ago.") + \ -+ "\nThis is an only server, meaning if it wins it will be the only winner" if \ -+ choice['onlyServer'] else "" - - pollMessage = await channel.send(embed=embed) - await channel.send('@everyone') -Index: .idea/dataSources.xml -IDEA additional info: -Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP -<+>\r\n\r\n \r\n \r\n mysql.8\r\n true\r\n com.mysql.cj.jdbc.Driver\r\n jdbc:mysql://192.168.1.52:5618/\r\n \r\n \r\n \r\n \r\n \r\n -Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP -<+>UTF-8 -=================================================================== -diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml ---- a/.idea/dataSources.xml (revision 9e407d37bc10832d7e9a5f106233446c700253a9) -+++ b/.idea/dataSources.xml (date 1616876395131) -@@ -8,6 +8,7 @@ - jdbc:mysql://192.168.1.52:5618/ - - -+ - - - diff --git a/.idea/shelf/Uncommitted_changes_before_Update_at_3_27_2021_4_05_PM__Default_Changelist_.xml b/.idea/shelf/Uncommitted_changes_before_Update_at_3_27_2021_4_05_PM__Default_Changelist_.xml deleted file mode 100644 index f7a007e..0000000 --- a/.idea/shelf/Uncommitted_changes_before_Update_at_3_27_2021_4_05_PM__Default_Changelist_.xml +++ /dev/null @@ -1,4 +0,0 @@ - - \ No newline at end of file diff --git a/scr/Modules/TMC/McRoll.py b/scr/Modules/TMC/McRoll.py index 7e82acc..08dbe96 100644 --- a/scr/Modules/TMC/McRoll.py +++ b/scr/Modules/TMC/McRoll.py @@ -1,4 +1,3 @@ -import collections from typing import Union import discord from discord.ext import commands