-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoll_cancel.py
44 lines (36 loc) · 1.62 KB
/
poll_cancel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/python3 -u
import discord
import os
from dotenv import load_dotenv
from discord.ext import commands
from datetime import datetime
load_dotenv()
client = commands.Bot(command_prefix='!')
@client.event
async def on_ready():
print('!poll_cancel started on bot {0.user}'.format(client))
@client.command()
#@commands.has_permissions(manage_messages=True)
async def poll_cancel(ctx, poll_num: int):
if ctx.channel.id == int(os.getenv('channel')):
return
if os.path.exists(str("poll" + str(poll_num) + ".tmp")):
poll_file = open(str("poll" + str(poll_num) + ".tmp"), "r")
poll_data = poll_file.readlines()
poll_file.close()
if str(poll_data[1]).strip() == str(ctx.author.id):
os.remove(str("poll" + str(poll_num) + ".tmp"))
await ctx.send("Cancelled poll #" + str(poll_num) + " by <@!" + str(poll_data[1]).strip() + ">")
elif ctx.author.guild_permissions.manage_messages:
os.remove(str("poll" + str(poll_num) + ".tmp"))
await ctx.send("Cancelled poll #" + str(poll_num) + " by <@!" + str(poll_data[1]).strip() + ">")
else:
await ctx.send("You can only cancel your own polls without mod status.")
print(str(str(datetime.now()) + str(ctx.author) + " attempted to delete a poll without permission"))
else:
await ctx.send("Poll #" + str(poll_num) + " not currently running")
@poll_cancel.error
async def poll_cancel_error(ctx, error):
if isinstance(error, discord.ext.commands.errors.MissingRequiredArgument):
await ctx.send("Must provide poll number to cancel")
client.run(os.getenv('TOKEN'))