\w* | [0-9]* | ([0-9]|,)* | ([0-9]+|Seconds?|Minutes?|"
+ r"Hours?)+ | [0-9]+")
+ needed_regex = re.compile(r" | ((\w|,)+ )+")
+
+ type_iter = type_regex.finditer(str(texte))
+ value_iter = value_regex.finditer(str(texte))
+ building_iter = building_regex.finditer(str(texte))
+ time_iter = time_regex.finditer(str(texte))
+ quantity_iter = quantity_regex.finditer(str(texte))
+ needed_iter = needed_regex.finditer(str(texte))
+
+ # Extract value from regex result
+ result["type"] = format_string(re.sub(r"Type ", "", str(type_iter.__next__().group(0))))
+ result["value"] = int(
+ re.sub(r"SellPrice ", "", str(value_iter.__next__().group(0))).replace(
+ ",", ""))
+ # Extract for recipe
+ try:
+ result["building"] = format_string(re.sub(
+ r"\w*iscreatedfromthisrecipe"
+ r"BuildingName | UnlockedatDepth | Cost"
+ r"ToUnlock | TimeRequired | AmountCreated | ItemsRequired | "
+ r"thead>\w*iscreatedfromthisrecipeBuildingName | UnlockedatDepth | CostToUnlock | TimeRequired | AmountCreated | ItemsRequired |
---|
\w* | [0-"
+ r"9]* | ([0-9]|,)* | ",
+ "",
+ str(time_iter.__next__().group(0))))
+ # Time:
+ time_str = time_str.replace("s", "") # remove plural
+ time_list = re.split("([0-9]+)", time_str)
+ if time_list[0] == '':
+ del time_list[0]
+ time = 0
+ for number, unit in zip(time_list[::2], time_list[1::2]):
+ if unit == "Second":
+ time += int(number)
+ elif unit == "Minute":
+ time += int(number) * 60
+ elif unit == "Hour":
+ time += int(number) * 60 * 60
+ result['time'] = int(time)
+
+ result["quantity"] = int(str(re.sub("\w*iscrea"
+ "tedfromthisrecipeBuild"
+ "ingName | UnlockedatDepth | CostToUnlock | TimeRequired<"
+ "/th> | AmountCreated | ItemsRequired |
---|
\w*([0-9]|,)* | ([0-9]|,)* | ([0-9]+|Seconds?"
+ "|Minutes?|Hours?)+ | ",
+ "",
+ quantity_iter.__next__().group(0))))
+ needed_text = re.sub(r" | ", "", needed_iter.__next__().group(0))
+
+ item_name_iter = re.finditer(r"[A-Za-z]+([0-9]|,)+", str(needed_text))
+
+ for item_name_match, item_quantity_match in zip(item_name_iter, item_quantity_iter):
+ item_name = re.sub(r"[A-Za-z]+", "", item_quantity_match.group(0)).replace(",", "").replace(
+ ".", ""))
+ result["needed"].update({format_string(item_name): item_quantity})
+
+
+ except StopIteration:
+ pass
+
+ return result
+
+
+def get_sector_info():
+ page = requests.get("https://deeptownguide.com/Areas/Resources")
+ texte = str(page.content).replace(" ", "").replace("\n", "").replace(r"\n", "")
+ line_regex = re.compile(r"[0-9]+(( \w* ([0-9]|\.|%)+| ) | )+")
+ num_regex = re.compile(r"[0-9]+")
+ item_regex = re.compile(r"( \w* ([0-9]|\.|%)+| )"
+ r" | ")
+ item_name_regex = re.compile(r"(([0-9]|\.)+")
+
+ line_iter = line_regex.finditer(texte)
+
+ etages = {}
+ liste_items = []
+ for line in line_iter:
+ etage_iter = num_regex.finditer(line.group(0))
+ etage = int(re.sub(r"", "", etage_iter.__next__().group(0)))
+ item_iter = item_regex.finditer(line.group(0))
+ items = {}
+ for item in item_iter:
+ name_iter = item_name_regex.finditer(item.group(0))
+ name = str(re.sub(r"(", "", quantity_iter.__next__().group(0))) / 100
+ items.update({name: quantity})
+ if name not in liste_items:
+ liste_items.append(name)
+ etages.update({str(etage): items})
+ etages.update({"0": {name: 0 for name in liste_items}})
+ return etages
+
+
+def update_data():
+ items = {}
+ urls_item = get_all_item_urls()
+ print(len(urls_item))
+ a = 0
+ for item_url in urls_item:
+ a += 1
+ items.update({
+ str(format_string(re.sub("https://deeptownguide.com/Items/Details/[0-9]+/", "", item_url))):
+ get_item_info(item_url)
+ })
+ print(a * 100 / len(urls_item), "%")
+ with open('items.json', "w") as dest_file:
+ json.dump(items, dest_file)
+ with open('mines.json', "w") as dest_file:
+ json.dump(get_sector_info(), dest_file)
+ return None
+
+
+if __name__ == "__main__":
+ print(get_item_info('https://deeptownguide.com/Items/Details/702/stage-ii'))
+ update_data()
diff --git a/bot/modules/directAccessDB.py b/bot/modules/directAccessDB.py
new file mode 100644
index 0000000..62fa107
--- /dev/null
+++ b/bot/modules/directAccessDB.py
@@ -0,0 +1,67 @@
+import os
+import time
+from textwrap import wrap
+
+import discord
+import traductions as tr
+
+
+def to_str(entier):
+ return str(entier).replace("1", "a").replace("2", "b").replace("3", "c").replace("4", "d").replace("5", "e") \
+ .replace("6", "f").replace("7", "g").replace("8", "h").replace("9", "i").replace("0", "j")
+
+def pp(cursor, data=None, rowlens=0):
+ d = cursor.description
+ if not d:
+ return "#### NO RESULTS ###"
+ names = []
+ lengths = []
+ rules = []
+ if not data:
+ data = cursor.fetchall()
+ for dd in d: # iterate over description
+ l = dd[1]
+ if not l:
+ l = 12 # or default arg ...
+ l = min(l, len(dd[0])) # Handle long names
+ names.append(dd[0])
+ print(dd)
+ lengths.append(l)
+ for col in range(len(lengths)):
+ if rowlens:
+ rls = [len(row[col]) for row in data if row[col]]
+ lengths[col] = max([lengths[col]]+rls)
+ rules.append("-"*lengths[col])
+ format = " ".join(["%%-%ss" % l for l in lengths])
+ result = [format % tuple(names)]
+ result.append(format % tuple(rules))
+ for row in data:
+ result.append(format % tuple([str(v) for v in row.values()]))
+ return "\n".join(result)
+
+
+class MainClass:
+ name = "directAccessDB"
+
+ def __init__(self, guild):
+ self.guild = guild
+
+ async def execute(self, msg, command, args):
+ if msg.author.id not in self.guild.config["master_admins"]:
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["PermissionError"])
+ return
+ with self.guild.bot.database.cursor() as cursor:
+ print(' '.join(args))
+ cursor.execute(' '.join(args))
+ self.guild.bot.database.commit()
+ string = pp(cursor)
+ for to_send in string.split("\n"):
+ await msg.channel.send("```"+to_send+"```")
+
+
+ async def on_message(self, msg):
+ if msg.content.startswith(self.guild.config["prefix"] * 2):
+ command, *args = msg.content.lstrip(self.guild.config["prefix"]).split(" ")
+ if command == "execute":
+ await self.execute(msg, command, args)
+ return
diff --git a/bot/modules/github.py b/bot/modules/github.py
index 4e3ab7b..0b3dddf 100644
--- a/bot/modules/github.py
+++ b/bot/modules/github.py
@@ -1,4 +1,5 @@
-from bot import traductions as tr
+import discord
+import traductions as tr
class MainClass:
diff --git a/bot/modules/help.py b/bot/modules/help.py
index 6bfc5cb..7d08369 100644
--- a/bot/modules/help.py
+++ b/bot/modules/help.py
@@ -1,4 +1,5 @@
-from bot import traductions as tr
+import discord
+import traductions as tr
class MainClass:
@@ -44,7 +45,7 @@ class MainClass:
texte += "\n"
texte += exemple[0].format(prefix=self.guild.config["prefix"])
texte += ": "
- texte += exemple[1]
+ texte += exemple[1].format(prefix=self.guild.config["prefix"])
await msg.channel.send(texte)
else:
await msg.channe.send(tr.tr[self.guild.config["lang"]]["errors"]["CommandNotFoundError"].format(command=fonction))
diff --git a/bot/modules/modules.py b/bot/modules/modules.py
index 0e9c4c1..8114084 100644
--- a/bot/modules/modules.py
+++ b/bot/modules/modules.py
@@ -1,5 +1,5 @@
import discord
-from bot import traductions as tr
+import traductions as tr
class MainClass:
diff --git a/bot/modules/pi.py b/bot/modules/pi.py
index a8401bd..efe5d19 100644
--- a/bot/modules/pi.py
+++ b/bot/modules/pi.py
@@ -1,6 +1,7 @@
+import os
import re
-from bot import traductions as tr
+import traductions as tr
class MainClass:
diff --git a/bot/modules/survey.py b/bot/modules/survey.py
new file mode 100644
index 0000000..6a71633
--- /dev/null
+++ b/bot/modules/survey.py
@@ -0,0 +1,384 @@
+import os
+import time
+
+import discord
+import traductions as tr
+
+
+def to_str(entier):
+ return str(entier).replace("1", "a").replace("2", "b").replace("3", "c").replace("4", "d").replace("5", "e") \
+ .replace("6", "f").replace("7", "g").replace("8", "h").replace("9", "i").replace("0", "j")
+
+
+class MainClass:
+ name = "survey"
+
+ def __init__(self, guild):
+ self.guild = guild
+ self.current_surveys = {}
+ self.create_table()
+
+ def create_table(self):
+ with self.guild.bot.database.cursor() as cursor:
+ create_survey_table_sql = "CREATE TABLE IF NOT EXISTS {guild_id}surveys (" \
+ " id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY," \
+ " title VARCHAR(2000) NOT NULL," \
+ " depart BIGINT," \
+ " duree BIGINT" \
+ ");".format(guild_id=self.guild.id)
+ create_choices_table_sql = "CREATE TABLE IF NOT EXISTS {guild_id}survey_choices (" \
+ " id int(20) NOT NULL AUTO_INCREMENT PRIMARY KEY," \
+ " survey int(20) NOT NULL," \
+ " content VARCHAR(1000)," \
+ " attachment BLOB(67108864)," \
+ " attachment_name VARCHAR(1000)" \
+ ");".format(guild_id=self.guild.id)
+ create_vote_table_sql = "CREATE TABLE IF NOT EXISTS {guild_id}survey_votes (" \
+ " id int NOT NULL AUTO_INCREMENT PRIMARY KEY," \
+ " choice BIGINT NOT NULL," \
+ " user_id VARCHAR(20) NOT NULL" \
+ ");".format(guild_id=self.guild.id)
+ cursor.execute(create_choices_table_sql)
+ cursor.execute(create_survey_table_sql)
+ cursor.execute(create_vote_table_sql)
+ self.guild.bot.database.commit()
+
+ async def vote(self, msg, command, args):
+ try:
+ await msg.delete()
+ except discord.Forbidden:
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["DiscordForbiddenError"])
+ if len(args) != 1:
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["NotEnoughParamError"])
+ return
+ try:
+ id_vote = int(args[0])
+ except ValueError:
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["NotANumberError"])
+ return
+
+ with self.guild.bot.database.cursor() as cursor:
+ # récupération de l'id du sondage
+ select_choice_sql = "SELECT survey FROM `{guild_id}survey_choices` WHERE id = %s;".format(
+ guild_id=self.guild.id)
+ cursor.execute(select_choice_sql, (id_vote))
+ survey_id = [r["survey"] for r in cursor.fetchall()]
+
+ if len(survey_id) == 0: # Le choix n'existe pas
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["SurveyNotExistsError"])
+ return
+
+ with self.guild.bot.database.cursor() as cursor:
+ # Récupération de la date de fin du sondage
+ select_survey_sql = "SELECT depart, duree FROM `{guild_id}surveys` WHERE id=%s;".format(
+ guild_id=self.guild.id)
+ cursor.execute(select_survey_sql, (survey_id))
+ r = cursor.fetchone()
+ if r["depart"] is not None:
+ fin = r["depart"] + r["duree"]
+ else:
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["NotYetPostedError"])
+ return
+ # Liste des précédents votes
+ select_prec_votes_sql = "SELECT choice FROM `{guild_id}survey_votes` WHERE user_id=%s;".format(
+ guild_id=self.guild.id)
+ cursor.execute(select_prec_votes_sql, (msg.author.id))
+ list_votes = [r["choice"] for r in cursor.fetchall()]
+ # Liste des précédents sondages votés
+ list_surveys_sql = "SELECT survey FROM `{guild_id}survey_choices` WHERE id=%s".format(
+ guild_id=self.guild.id)
+ list_surveys = []
+ for id_choice in list_votes:
+ cursor.execute(list_surveys_sql, (id_choice))
+ list_surveys.append(cursor.fetchone()["survey"])
+
+ if fin < time.time(): # Sondage terminé
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["SurveyCompletedError"])
+ return
+ if survey_id[0] in list_surveys: # Déjà voté
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["AlreadyVote"])
+ return
+
+ # On peu voter, on insère dans la bdd
+ with self.guild.bot.database.cursor() as cursor:
+ sql_insert = "INSERT INTO `{guild_id}survey_votes` (choice, user_id) VALUES (%s, %s);" \
+ .format(guild_id=self.guild.id)
+ cursor.execute(sql_insert, (id_vote, msg.author.id))
+ self.guild.bot.database.commit()
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["modules"]["survey"]["vote"]
+ .format(id_auteur=msg.author.id))
+
+ async def add_choice(self, msg, command, args):
+ # L'utilisateur est un administrateur du bot
+ if msg.author.id not in self.guild.config["master_admins"]:
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["PermissionError"])
+ return
+ # Vérification du nombre de paramètres
+ if len(args) < 2 or (len(args) < 1 and len(msg.attachments) < 1):
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["NotEnoughParamError"])
+ return
+
+ try: # Tentative de conversion en nombre
+ survey_id = int(args[0])
+ except ValueError:
+ msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["NotANumberError"])
+ return
+
+ # Vérification de l'existance du sondage
+ with self.guild.bot.database.cursor() as cursor:
+ sql_id = "SELECT id FROM `{guild_id}surveys`".format(guild_id=self.guild.id)
+ cursor.execute(sql_id, ())
+ liste_id = [r["id"] for r in cursor.fetchall()]
+
+ if survey_id not in liste_id: # Le sondage n'existe pas
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["SurveyNotExistsError"])
+ return
+
+ # Verification que le sondage n'a pas déjà été publié
+ with self.guild.bot.database.cursor() as cursor:
+ sql_depart = "SELECT depart FROM `{guild_id}surveys` WHERE id = %s".format(guild_id=self.guild.id)
+ cursor.execute(sql_depart, (survey_id))
+ depart = cursor.fetchone()["depart"]
+ if depart is not None:
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["AlreadySendSurvey"])
+ return
+
+ content = " ".join(args[1:])
+ # Ecriture du fichier temporaire
+ with open("temp_attachement" + str(survey_id), "w") as temp_file:
+ temp_file.write("")
+ file_name = ""
+ # Si un fichier est présent dans le message on le sauvegarde
+ if len(msg.attachments) > 0:
+ attachment = msg.attachments[0]
+ if attachment.size > 67108864:
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["AttachementTooBigError"])
+ return
+ with open("temp_attachement" + str(survey_id), "wb") as temp_file:
+ await attachment.save(temp_file)
+ file_name = attachment.filename
+ # On insère le choix dans la base de données
+ with self.guild.bot.database.cursor() as cursor:
+ sql_insert = "INSERT INTO `{guild_id}survey_choices` (survey, content, attachment, attachment_name) VALUES (%s, %s, %s, %s)".format(
+ guild_id=self.guild.id)
+ with open("temp_attachement" + str(survey_id), "rb") as temp_file:
+ cursor.execute(sql_insert, (survey_id, content, temp_file.read(), file_name))
+ os.remove("temp_attachement" + str(survey_id))
+ self.guild.bot.database.commit()
+
+ async def create_survey(self, msg, command, args):
+ if msg.author.id not in self.guild.config["master_admins"]:
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["PermissionError"])
+ return
+
+ if len(args) < 2:
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["NotEnoughParamError"])
+ return
+ else:
+ date_str = args[0]
+ content = " ".join(args[1:])
+
+ day_split = date_str.split("d")
+ if len(day_split) == 1 and "d" not in date_str:
+ jours = "0"
+ next_split = date_str
+ elif "d" in date_str and day_split[1] == "":
+ jours = day_split[0]
+ next_split = "0h0m0s"
+ else:
+ jours = day_split[0]
+ next_split = day_split[1]
+
+ hour_split = next_split.split("h")
+ if len(hour_split) == 1 and "h" not in date_str:
+ heures = "0"
+ next_split = date_str
+ elif "h" in date_str and hour_split[1] == "":
+ heures = hour_split[0]
+ next_split = "0m0s"
+ else:
+ heures = hour_split[0]
+ next_split = hour_split[1]
+
+ minute_split = next_split.split("m")
+ if len(minute_split) == 1 and "h" not in date_str:
+ minutes = "0"
+ next_split = date_str
+ elif "m" in date_str and minute_split[1] == "":
+ minutes = minute_split[0]
+ next_split = "0s"
+ else:
+ minutes = minute_split[0]
+ next_split = minute_split[1]
+
+ second_split = next_split.split("s")
+ if len(second_split) == 1 and "s" not in date_str:
+ secondes = "0"
+ else:
+ secondes = second_split[0]
+
+ try:
+ jours = int(jours)
+ heures = int(heures)
+ minutes = int(minutes)
+ secondes = int(secondes)
+ except ValueError:
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["NotANumberError"])
+ return
+
+ total = jours * 24 * 60 * 60 + heures * 60 * 60 + minutes * 60 + secondes # Durée du sondage
+
+ with self.guild.bot.database.cursor() as cursor:
+ insert_sql = "INSERT INTO `{guild_id}surveys` (title, duree) VALUES (%s, %s);".format(
+ guild_id=self.guild.id)
+ cursor.execute(insert_sql, (content, total))
+ self.guild.bot.database.commit()
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["modules"]["survey"]["create_survey"]
+ .format(id=cursor.lastrowid, prefix=self.guild.config["prefix"]))
+
+ async def post_survey(self, msg, command, args):
+ if msg.author.id not in self.guild.config["master_admins"]:
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["PermissionError"])
+ return
+
+ if len(args) != 1:
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["NotEnoughParamError"])
+ return
+ try:
+ survey_id = int(args[0])
+ except ValueError:
+ msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["NotANumberError"])
+ return
+ # Vérification de l'existance du sondage
+ with self.guild.bot.database.cursor() as cursor:
+ sql_id = "SELECT id FROM `{guild_id}surveys`".format(guild_id=self.guild.id)
+ cursor.execute(sql_id)
+ liste_id = [r["id"] for r in cursor.fetchall()]
+ if survey_id not in liste_id:
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["SurveyNotExistsError"])
+ return
+ # Verification que le sondage n'a pas déjà été publié
+ with self.guild.bot.database.cursor() as cursor:
+ sql_depart = "SELECT depart FROM `{guild_id}surveys` WHERE id = %s".format(guild_id=self.guild.id)
+ cursor.execute(sql_depart, (survey_id))
+ depart = cursor.fetchone()["depart"]
+ if depart is not None:
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["AlreadySendSurvey"])
+ return
+ # Envoi du sondage
+ with self.guild.bot.database.cursor() as cursor:
+ sql_update = "UPDATE `{guild_id}surveys` SET depart = %s WHERE id=%s" \
+ .format(guild_id=self.guild.id)
+ cursor.execute(sql_update, (int(time.time()), survey_id))
+ self.guild.bot.database.commit()
+ with self.guild.bot.database.cursor() as cursor:
+ sql_choices = "SELECT id from `{guild_id}survey_choices` WHERE survey=%s" \
+ .format(guild_id=self.guild.id)
+ cursor.execute(sql_choices, (survey_id))
+ choices_id = [r["id"] for r in cursor.fetchall()]
+ with self.guild.bot.database.cursor() as cursor:
+ sql_survey_title = "SELECT title, duree FROM `{guild_id}surveys` WHERE id = %s" \
+ .format(guild_id=self.guild.id)
+ cursor.execute(sql_survey_title, (survey_id))
+ result = cursor.fetchone()
+ # Envoi des messages de présentation
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["modules"]["survey"]["post_survey"]["presentation"]
+ .format(prefix=self.guild.config["prefix"], heures=int(result["duree"] / 3600)))
+ await msg.channel.send(result['title'])
+ # Envoi des message pour chaque choix
+ for choice_id in choices_id:
+ with self.guild.bot.database.cursor() as cursor:
+ sql_choice = "SELECT id,content, attachment, attachment_name FROM `{guild_id}survey_choices` WHERE id=%s" \
+ .format(guild_id=self.guild.id)
+ cursor.execute(sql_choice, (choice_id))
+ result = cursor.fetchone()
+ if result["attachment_name"]:
+ with open(result["attachment_name"], "wb") as temp_file:
+ temp_file.write(result["attachment"])
+ with open(result["attachment_name"], "rb") as temp_file:
+ await msg.channel.send("`{prefix}vote {id}` "
+ .format(prefix=self.guild.config["prefix"], id=result["id"]) + result[
+ "content"],
+ file=discord.File(temp_file, filename=str(result["attachment_name"])))
+ else:
+ await msg.channel.send(content="`{prefix}vote {id}` "
+ .format(prefix=self.guild.config["prefix"], id=result["id"]) + result["content"])
+
+ async def post_result(self, msg, command, args):
+ # L'auteur est-t-il un admin?
+ if msg.author.id not in self.guild.config["master_admins"]:
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["PermissionError"])
+ return
+ # Nombre de paramètres
+ if len(args) != 1:
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["NotEnoughParamError"])
+ return
+ try:
+ survey_id = int(args[0])
+ except ValueError:
+ msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["NotANumberError"])
+ return
+ # Vérification de l'existance du sondage
+ with self.guild.bot.database.cursor() as cursor:
+ sql_id = "SELECT id FROM `{guild_id}surveys`".format(guild_id=self.guild.id)
+ cursor.execute(sql_id)
+ liste_id = [r["id"] for r in cursor.fetchall()]
+ if survey_id not in liste_id:
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["SurveyNotExistsError"])
+ return
+ # Vérification que le sondage est terminé
+ with self.guild.bot.database.cursor() as cursor:
+ # Récupération de la date de fin du sondage
+ select_survey_sql = "SELECT depart, duree FROM `{guild_id}surveys` WHERE id=%s;".format(
+ guild_id=self.guild.id)
+ cursor.execute(select_survey_sql, (survey_id))
+ r = cursor.fetchone()
+ if r["depart"] is not None:
+ fin = r["depart"] + r["duree"]
+ else:
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["NotYetPostedError"])
+ return
+ print(fin, time.time())
+ if fin > time.time():
+ await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["NotYetFinishedError"])
+ return
+
+ # Récupération des choix
+ with self.guild.bot.database.cursor() as cursor:
+ sql_select_choices = "SELECT id FROM `{guild_id}survey_choices` WHERE survey=%s;".format(guild_id=self.guild.id)
+ cursor.execute(sql_select_choices, (survey_id))
+ choices = [r["id"] for r in cursor.fetchall()]
+
+ # Récupération des votes
+ votes = []
+ for id_choice in choices:
+ with self.guild.bot.database.cursor() as cursor:
+ select_votes_sql = "SELECT id FROM `{guild_id}survey_votes` WHERE choice=%s;".format(guild_id=self.guild.id)
+ cursor.execute(select_votes_sql, (id_choice))
+ votes.append((id_choice,len(cursor.fetchall())))
+
+ votes.sort(key=lambda x: x[1])
+ total = sum([x[1] for x in votes])
+ texte = tr.tr[self.guild.config["lang"]]["modules"]["survey"]["result"]["text"]+"```"
+ i=0
+ for vote in votes[::-1]:
+ i+=1
+ texte += "\n n°{i} - Choix {id_choix} - {nb_votes} ({pourcentage}%)"\
+ .format(i=i, id_choix=vote[0], nb_votes=vote[1], pourcentage=vote[1]*100/total)
+ texte += "```"
+ await msg.channel.send(texte)
+
+ async def on_message(self, msg):
+ if msg.content.startswith(self.guild.config["prefix"]):
+ command, *args = msg.content.lstrip(self.guild.config["prefix"]).split(" ")
+ if command == "vote":
+ await self.vote(msg, command, args)
+ elif command == "add_choice":
+ await self.add_choice(msg, command, args)
+ elif command == "create_survey":
+ await self.create_survey(msg, command, args)
+ elif command == "post_survey":
+ await self.post_survey(msg, command, args)
+ elif command == "post_results":
+ await self.post_result(msg, command, args)
+ return
diff --git a/bot/modules/tools.py b/bot/modules/tools.py
index 8c5b6a4..055af36 100644
--- a/bot/modules/tools.py
+++ b/bot/modules/tools.py
@@ -1,7 +1,7 @@
import time
import discord
-from bot import traductions as tr
+import traductions as tr
class MainClass:
diff --git a/main.py b/main.py
index 436dc7a..21cf92a 100644
--- a/main.py
+++ b/main.py
@@ -76,7 +76,7 @@ foBot = FoBot(db_connection=db_connection)
foWeb = FoWeb(bot=None, db=db_connection)
-bot_app = foBot.start(os.environ['DISCORD_TOKEN'], max_messages=100000000)
+bot_app = foBot.start(os.environ['FOBOT_DISCORD_TOKEN'], max_messages=100000000)
bot_task = asyncio.ensure_future(bot_app)
foWeb.listen(port=8888)
| | | |