mirror of
https://gitlab.jonasled.de/jonasled/discordbot
synced 2024-06-03 10:21:08 +02:00
only the poll owner can end it
This commit is contained in:
parent
ed02cbc010
commit
4592829f42
13
bot.py
13
bot.py
|
@ -106,7 +106,7 @@ async def on_raw_reaction_add(message): #this runs on every reaction
|
|||
dbcursor.execute("UPDATE MESSAGES SET reactionXP = ? WHERE user = ? AND server = ?", [messages, message.user_id, message.guild_id])#update the reactionXP with the new values
|
||||
|
||||
try:
|
||||
polls[str(message.message_id)] # check if the reaction is on a poll
|
||||
polls[str(message.message_id)][0] # check if the reaction is on a poll
|
||||
calls = dbcursor.execute("SELECT calls FROM poll WHERE pollID = ? AND reaction = ?", [message.message_id, str(message.emoji)]).fetchone()[0]# if yes update the database and add 1 vote
|
||||
dbcursor.execute("UPDATE poll SET calls = ? WHERE pollID = ? AND reaction = ?", [calls + 1, message.message_id, str(message.emoji)])
|
||||
except:
|
||||
|
@ -126,7 +126,7 @@ async def on_raw_reaction_add(message): #this runs on every reaction
|
|||
@bot.event
|
||||
async def on_raw_reaction_remove(message):
|
||||
try:
|
||||
polls[str(message.message_id)] #check if the message is a poll
|
||||
polls[str(message.message_id)][0] #check if the message is a poll
|
||||
calls = dbcursor.execute("SELECT calls FROM poll WHERE pollID = ? AND reaction = ?", [message.message_id, str(message.emoji)]).fetchone()[0]#if yes update the database and remove 1 vote
|
||||
dbcursor.execute("UPDATE poll SET calls = ? WHERE pollID = ? AND reaction = ?", [calls - 1, message.message_id, str(message.emoji)])
|
||||
except:
|
||||
|
@ -338,7 +338,7 @@ async def poll(ctx, question, *options: str):#this is a tool to create a poll
|
|||
embed = discord.Embed(title=question, description=description)#prepare the response
|
||||
await ctx.message.channel.send("@everyone")#tag everyone, for the new survey
|
||||
react_message = await ctx.message.channel.send(embed=embed)#print the survey and save the message to a variable
|
||||
polls[str(react_message.id)] = react_message#save the react message to the polls array to acces it later
|
||||
polls[str(react_message.id)] = [react_message, ctx.message.author.id]#save the react message and the userid to the polls array to acces it later
|
||||
for reaction in reactions[:len(options)]:#for every reaction add an entry to the reaction database and add it to the message, that the user can click it
|
||||
dbcursor.execute("INSERT INTO poll VALUES (?, ?, 0)", [react_message.id, reaction])
|
||||
await react_message.add_reaction(reaction)
|
||||
|
@ -357,7 +357,12 @@ async def poll(ctx, question, *options: str):#this is a tool to create a poll
|
|||
|
||||
@bot.command(pass_context=True, brief="shows the result of a poll, give the poll ID as argument")
|
||||
async def result(ctx, id):#this function prints the result of a poll
|
||||
poll_message = polls[str(id)]#get the poll message from the variable
|
||||
poll_message = polls[str(id)][0]#get the poll message from the variable
|
||||
poll_owner = polls[str(id)][1]
|
||||
if(poll_owner != ctx.message.author.id): #check if the poll owner wants the result, or someone else
|
||||
await ctx.message.channel.send("You can only get the results of your poll.")
|
||||
return
|
||||
|
||||
embed = poll_message.embeds[0]#get the embed (the content)
|
||||
|
||||
del polls[str(id)]#delte the poll from the poll message array
|
||||
|
|
Loading…
Reference in a new issue