async def synctables(message): if access.isowner(message.guild, message.author): channels = message.guild.channels response = "Syncing table permissions to category." await message.channel.send(response.format(message)) for channel in channels: if "table" in channel.name.lower(): time.sleep(0.5) print("Syncing permissions for channel " + channel.name + ".") await channel.edit(sync_permissions=True) response = "All table permissions synced to category." await message.channel.send(response.format(message)) embed = discord.Embed(title="Sync Table Permission to Category", color=discord.Colour.orange() ) #description=message.mentions[0].display_name now = datetime.datetime.utcnow() embed.set_footer(text="Logged: " + now.strftime("%Y-%m-%d %H:%M:%S") + " UTC") logchannel = discord.utils.get(message.guild.channels, name="corgi-logs") await logchannel.send(embed=embed)
async def purgeroles(message): if access.isowner(message.guild, message.author): if len(message.mentions) == 1: for role in message.mentions[0].roles: if role.name.lower() != "@everyone": try: await message.mentions[0].remove_roles(role) except: response = "Unable to remove role " + role.name + "." await message.channel.send(response.format(message)) response = "All roles removed from user." await message.channel.send(response.format(message)) embed = discord.Embed( title="Removed roles from User", color=discord.Colour.orange( )) #description=message.mentions[0].display_name now = datetime.datetime.utcnow() embed.set_footer(text="Logged: " + now.strftime("%Y-%m-%d %H:%M:%S") + " UTC") logchannel = discord.utils.get(message.guild.channels, name="corgi-logs") await logchannel.send(embed=embed)
async def addevent(client, message): def isdate(m): return m.author.id == message.author.id and m.channel.id == message.channel.id and re.match( "[2][0-1][0-9][0-9]-[0-1][0-9]-[0-3][0-9]", m.content) and validatedate(m.content) def booleanResponse(r, u): return r.message.id == respond.id and u.id == message.author.id and r.emoji in ( "✅", "❎") if isowner(message.guild, message.author) or isadmin( message.guild, message.author) or isheadjudge( message.guild, message.author): if message.content[10:] == "": response = "Event requires a name to be created." await message.channel.send(response.format(message)) return else: eventname = message.content[10:] response = "What is the start date of the event? (Format required is `yyyy-MM-dd`)" await message.channel.send(response.format(message)) try: inputdate = await client.wait_for('message', check=isdate, timeout=30) except: response = "No response received. Event creation cancelled." await message.channel.send(response.format(message)) startdate = datetime.strptime(inputdate.content, '%Y-%m-%d') response = "What is the end date of the event? (Format required is `yyyy-MM-dd`)" await message.channel.send(response.format(message)) try: inputdate = await client.wait_for('message', check=isdate, timeout=30) except: response = "No response received. Event creation cancelled." await message.channel.send(response.format(message)) enddate = datetime.strptime(inputdate.content, '%Y-%m-%d') if enddate < startdate: response = "The Event cannot end before it has started. Event creation cancelled" await message.channel.send(response.format(message)) return response = "Is this a Team Event?" respond = await message.channel.send(response.format(message)) await respond.add_reaction(greenTick) await respond.add_reaction(greenCross) #Get that reaction reply = None try: reply = await client.wait_for('reaction_add', check=booleanResponse, timeout=10) except: response = "No response received. Assumed solos event." await message.channel.send(response.format(message)) if reply is None or reply[0].emoji == greenCross: teams = 0 teamchannels = 0 else: teams = 1 if teams == 1: response = "Would you like teams that register to have Team Channels created, if they do not already have one?" respond = await message.channel.send(response.format(message)) await respond.add_reaction(greenTick) await respond.add_reaction(greenCross) #Get that reaction reply = None try: reply = await client.wait_for('reaction_add', check=booleanResponse, timeout=10) except: response = "No response received. Assumed channels are not required." await message.channel.send(response.format(message)) if reply is None or reply[0].emoji == greenCross: teamchannels = 0 else: teamchannels = 1 with pyodbc.connect(SQLConnString, timeout=20) as sqlConn: with sqlConn.cursor() as cursor: cursor.execute('EXEC corgi.AddEvent ?, ?, ?, ?, ?, ?, ?;', message.guild.id, eventname, startdate, enddate, teams, teamchannels, message.author.id) for row in cursor: eventid = row[0] cursor.commit() #cursor.close() response = "Event Created." await message.channel.send(response.format(message)) #Log details embed = discord.Embed(title="Create Event", color=discord.Colour.orange()) embed.add_field(name="Created By", value=message.author.display_name, inline=False) embed.add_field(name="Created By ID", value=message.author.id, inline=False) embed.add_field(name="Event Name", value=eventname, inline=False) embed.add_field(name="Event ID", value=eventid, inline=False) now = datetime.utcnow() embed.set_footer(text="Logged: " + now.strftime("%Y-%m-%d %H:%M:%S") + " UTC") logchannel = discord.utils.get(message.guild.channels, name="corgi-logs") await logchannel.send(embed=embed) return
async def deletedetail(client, message): def booleanResponse(r, u): return r.message.id == respond.id and u.id == message.author.id and r.emoji in ( "✅", "❎") if isowner(message.guild, message.author) or isadmin( message.guild, message.author) or isheadjudge( message.guild, message.author): if message.content[14:] == "": response = "Requires Detail ID to edit." await message.channel.send(response.format(message)) return elif not (message.content[14:].isdecimal()): response = "Invalid detail ID." await message.channel.send(response.format(message)) return else: detailid = message.content[14:] with pyodbc.connect(SQLConnString, timeout=20) as sqlConn: with getdetail(message.guild, detailid, sqlConn) as detail: if detail is None: response = "Invalid detail ID; detail does not exist." await message.channel.send(response.format(message)) return for row in detail: eventname = row[1] detailname = row[7] #detail.close() response = "Are you sure you want to delete the detail " + detailname + " for the event " + eventname + "?" respond = await message.channel.send(response.format(message)) await respond.add_reaction(greenTick) await respond.add_reaction(greenCross) #Get that reaction reply = None try: reply = await client.wait_for('reaction_add', check=booleanResponse, timeout=10) except: response = "No response received. Deletion cancelled." await message.channel.send(response.format(message)) return if reply is None or reply[0].emoji == greenCross: response = "Deletion cancelled." await message.channel.send(response.format(message)) return else: with pyodbc.connect(SQLConnString, timeout=20) as sqlConn: with sqlConn.cursor() as cursor: cursor.execute('EXEC corgi.DeleteDetail ?, ?;', message.guild.id, detailid) cursor.commit() #cursor.close() response = "Detail Deleted." await message.channel.send(response.format(message)) #Log details embed = discord.Embed(title="Delete Event Detail", color=discord.Colour.orange()) embed.add_field(name="Deleted By", value=message.author.display_name, inline=False) embed.add_field(name="Deleted By ID", value=message.author.id, inline=False) embed.add_field(name="Detail Name", value=detailname, inline=False) embed.add_field(name="Detail ID", value=detailid, inline=False) now = datetime.utcnow() embed.set_footer(text="Logged: " + now.strftime("%Y-%m-%d %H:%M:%S") + " UTC") logchannel = discord.utils.get(message.guild.channels, name="corgi-logs") await logchannel.send(embed=embed) return
async def editevent(client, message): def editResponse(r, u): return r.message.id == respond.id and u.id == message.author.id and emojidigits[ r.emoji] <= reactions def isuser(m): return m.author.id == message.author.id and m.channel.id == message.channel.id def isdate(m): return m.author.id == message.author.id and m.channel.id == message.channel.id and re.match( "[2][0-1][0-9][0-9]-[0-1][0-9]-[0-3][0-9]", m.content) and validatedate(m.content) def booleanResponse(r, u): return r.message.id == respond.id and u.id == message.author.id and r.emoji in ( "✅", "❎") if isowner(message.guild, message.author) or isadmin( message.guild, message.author) or isheadjudge( message.guild, message.author): if message.content[11:] == "": response = "Requires Event ID to edit." await message.channel.send(response.format(message)) return elif not (message.content[11:].isdecimal()): response = "Invalid event ID." await message.channel.send(response.format(message)) return else: eventid = message.content[11:] with pyodbc.connect(SQLConnString, timeout=20) as sqlConn: event = getevent(message.guild, eventid, sqlConn) if event is None: response = "Invalid event ID; event does not exist." await message.channel.send(response.format(message)) return for row in event: eventname = row[1] startdate = row[2] enddate = row[3] teamevent = row[4] channels = row[5] event.close() response = "What would you like to amend?\n" + digitemojis[ 1] + ": Event Name\n" + digitemojis[ 2] + ": Start Date\n" + digitemojis[ 2] + ": End Date\n" + digitemojis[4] + ": Event Type" reactions = 4 if teamevent == 1: response = response + "\n" + digitemojis[5] + ": Team Channels" reactions = 5 respond = await message.channel.send(response.format(message)) await respond.add_reaction(digitemojis[1]) await respond.add_reaction(digitemojis[2]) await respond.add_reaction(digitemojis[3]) await respond.add_reaction(digitemojis[4]) if reactions == 5: await respond.add_reaction(digitemojis[5]) try: reply = await client.wait_for('reaction_add', check=editResponse, timeout=10) except: response = "No response received. Editting cancelled." await message.channel.send(response.format(message)) return replyoption = emojidigits[reply[0].emoji] if replyoption == 1: response = "What is the new name of the event?" await message.channel.send(response.format(message)) try: reply = await client.wait_for('message', check=isuser, timeout=30) except: response = "No response received. Editting cancelled." await message.channel.send(response.format(message)) return eventname = reply.content elif replyoption == 2: response = "What is the new start date of the event? (Format required is `yyyy-MM-dd`)" await message.channel.send(response.format(message)) try: reply = await client.wait_for('message', check=isdate, timeout=30) except: response = "No response received. Editting cancelled." await message.channel.send(response.format(message)) return startdate = datetime.strptime(reply.content, '%Y-%m-%d').date() if startdate > enddate: response = "Start date cannot be after end date of Event. Editting cancelled." await message.channel.send(response.format(message)) return elif replyoption == 3: response = "What is the new end date of the event? (Format required is `yyyy-MM-dd`)" await message.channel.send(response.format(message)) try: reply = await client.wait_for('message', check=isdate, timeout=30) except: response = "No response received. Editting cancelled." await message.channel.send(response.format(message)) return enddate = datetime.strptime(reply.content, '%Y-%m-%d').date() if startdate > enddate: response = "End date cannot be before start date of Event. Editting cancelled." await message.channel.send(response.format(message)) return elif replyoption == 4: response = "Make event a Team Event?" respond = await message.channel.send(response.format(message)) await respond.add_reaction(greenTick) await respond.add_reaction(greenCross) #Get that reaction reply = None try: reply = await client.wait_for('reaction_add', check=booleanResponse, timeout=10) except: response = "No response received. Assumed solos event." await message.channel.send(response.format(message)) if reply is None or reply[0].emoji == greenCross: teamevent = 0 channels = 0 else: teamevent = 1 if teamevent == 1: response = "Would you like teams that register to have Team Channels created, if they do not already have one?" respond = await message.channel.send( response.format(message)) await respond.add_reaction(greenTick) await respond.add_reaction(greenCross) #Get that reaction reply = None try: reply = await client.wait_for('reaction_add', check=booleanResponse, timeout=10) except: response = "No response received. Assumed channels are not required." await message.channel.send(response.format(message)) if reply is None or reply[0].emoji == greenCross: channels = 0 else: channels = 1 elif replyoption == 5: response = "Would you like teams that register to have Team Channels created, if they do not already have one?" respond = await message.channel.send(response.format(message)) await respond.add_reaction(greenTick) await respond.add_reaction(greenCross) #Get that reaction reply = None try: reply = await client.wait_for('reaction_add', check=booleanResponse, timeout=10) except: response = "No response received. Assumed channels are not required." await message.channel.send(response.format(message)) if reply is None or reply[0].emoji == greenCross: channels = 0 else: channels = 1 with pyodbc.connect(SQLConnString, timeout=20) as sqlConn: with sqlConn.cursor() as cursor: cursor.execute('EXEC corgi.EditEvent ?, ?, ?, ?, ?, ?, ?;', message.guild.id, eventid, eventname, startdate, enddate, teamevent, channels) cursor.commit() #cursor.close() response = "Event Amended." await message.channel.send(response.format(message)) #Log details embed = discord.Embed(title="Event Amended", color=discord.Colour.orange()) embed.add_field(name="Amended By", value=message.author.display_name, inline=False) embed.add_field(name="Amended By ID", value=message.author.id, inline=False) embed.add_field(name="Event Name", value=eventname, inline=False) embed.add_field(name="Event ID", value=eventid, inline=False) now = datetime.utcnow() embed.set_footer(text="Logged: " + now.strftime("%Y-%m-%d %H:%M:%S") + " UTC") logchannel = discord.utils.get(message.guild.channels, name="corgi-logs") await logchannel.send(embed=embed) return
async def adddetail(client, message): def isuser(m): return m.author.id == message.author.id and m.channel.id == message.channel.id if isowner(message.guild, message.author) or isadmin( message.guild, message.author) or isheadjudge( message.guild, message.author): if message.content[16:] == "": response = "Requires Event ID to add a detail." await message.channel.send(response.format(message)) return elif not (message.content[16:].isdecimal()): response = "Invalid event ID." await message.channel.send(response.format(message)) return else: eventid = int(message.content[16:]) with pyodbc.connect(SQLConnString, timeout=20) as sqlConn: with getevent(message.guild, eventid, sqlConn) as event: if event is None: response = "Invalid event ID; event does not exist." await message.channel.send(response.format(message)) return #event.close() response = "What is the name of the detail you want to add?" await message.channel.send(response.format(message)) try: detailname = await client.wait_for('message', check=isuser, timeout=30) except: response = "No response received. Detail amendedment cancelled." await message.channel.send(response.format(message)) return response = "What is the detail you want to add?" await message.channel.send(response.format(message)) try: detail = await client.wait_for('message', check=isuser, timeout=120) except: response = "No response received. Detail amendedment cancelled." await message.channel.send(response.format(message)) return with pyodbc.connect(SQLConnString, timeout=20) as sqlConn: with sqlConn.cursor() as cursor: cursor.execute('EXEC corgi.AddDetail ?, ?, ?;', eventid, detailname.content, detail.content) for row in cursor: detailid = row[0] cursor.commit() #cursor.close() response = "Detail has been added to the event." await message.channel.send(response.format(message)) #Log details embed = discord.Embed(title="Add Event Detail", color=discord.Colour.orange()) embed.add_field(name="Added By", value=message.author.display_name, inline=False) embed.add_field(name="Added By ID", value=message.author.id, inline=False) embed.add_field(name="Detail Name", value=detailname.content, inline=False) embed.add_field(name="Detail ID", value=detailid, inline=False) now = datetime.utcnow() embed.set_footer(text="Logged: " + now.strftime("%Y-%m-%d %H:%M:%S") + " UTC") logchannel = discord.utils.get(message.guild.channels, name="corgi-logs") await logchannel.send(embed=embed) await eventdetails(message, eventid) return
async def on_message(message): if message.author == client.user: return elif message.author.bot: print('Message from bot {0.author}: {0.content}'.format(message)) return if not (debugon is None): print('Message from {0.author}: {0.content}'.format(message)) if message.channel.type == discord.ChannelType.private: if message.content.lower().startswith("$redeem"): await redeem.redeempurchase(client, message) return serverRoles = message.guild.roles roles = message.author.roles ##This is the old way ##isCommittee = False ##isCaptain = False ##isJudge = False ##isThom = False ##for role in roles: ## #As people, by design, can't have multiple rules, then we can safely break and not loop around 40~ roles ## if role.name == "Thom": ## isThom = True ## if role.name == "VTC Committee" or role.name == "Thom": ## isCommittee = True ## if role.name == "Head Judge": ## isHeadJudge = True ## if role.name == "Judge": ## isJudge = True ## if role.name == "Team Captain": ## isCaptain = True #random sticks rng = random.randint(1, 500) stick = client.get_emoji(735827082151723029) #print("Random Number was: " + str(rng)) if rng == 99: image = directory + "/images/corgilurk.gif" await message.channel.send(file=discord.File(image)) if "corgistick" in message.content: response = "No take! *Only* throw." await message.channel.send(response.format(message)) if "wednesday" in message.content.lower(): day_name = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ] day = datetime.utcnow().weekday() if day_name[day] == "Wednesday": image = directory + "/images/wednesday.jpg" await message.channel.send(file=discord.File(image)) if message.clean_content.lower( ) == "time for bed @corgi" and message.author.id == owner: response = "*Stretches and gets into bed.*" await message.channel.send(response.format(message)) sys.exit() return if message.content.lower() == "$help": response = "Please visit the following link for help on my available commands: <https://fishcord.larnu.uk/corgi-help/>" await message.channel.send(response.format(message)) return if message.content.lower() == "how i throw": rules = rulewordings.throwrules() for rule in rules: await message.channel.send(rule.format(message)) return if message.content.lower() == "how i slam": rules = rulewordings.slamrules() for rule in rules: await message.channel.send(rule.format(message)) return if message.content.lower() == "how i attack": rules = rulewordings.attackrules() for rule in rules: await message.channel.send(rule.format(message)) return if message.content.lower() == "how i activate": rules = rulewordings.activaterules() for rule in rules: await message.channel.send(rule.format(message)) return if message.content.lower() == "how i spell": rules = rulewordings.spellcastrules() for rule in rules: await message.channel.send(rule.format(message)) return if message.content.lower().startswith("$mute"): await access.muteuser(message) return if message.content.lower().startswith("$unmute"): await access.unmuteuser(message) return for mentions in message.mentions: if mentions.id == message.guild.me.id: await message.channel.send("Woof?") break if message.content.lower() == ("$github"): response = "You can find my master's github here: https://github.com/LarnuUK" await message.channel.send(response.format(message)) return if message.content.lower() == "$timezones": response = "" embed = discord.Embed( title="Available Timezones", description= "Timezones available for the conversion commands (such as `$CEST` and `$NZDT`)", color=colourings["dark gold"]) for tz in timezones: tzdata = timezones[tz] tzname = tzdata["Name"] tzoffset = tzdata["Offset"] if tzoffset < 0: offset = str(tzoffset) else: offset = "+" + str(tzoffset) response = response + "\n**" + tz + "**: " + tzname + " (UTC " + offset + ")" embed.add_field(name="Timezones", value=response, inline=False) await message.channel.send(embed=embed) return if message.content.lower().startswith("$") and " " in message.content: if validatetz(message.content.upper()[1:message.content.index(" ")]): spaceindex = message.content.index(" ") sourcetz = message.content.upper()[1:spaceindex] time = message.content[spaceindex + 1:spaceindex + 6] hours = message.content[spaceindex + 1:spaceindex + 3] minutes = message.content[spaceindex + 4:spaceindex + 6] desttz = message.content.upper()[spaceindex + 7:] if re.match("[0-9][0-9]:[0-5][0-9]", time): try: tzdestination = timezones[desttz] tzsource = timezones[sourcetz] except: response = "Invalid or unrecognised timezone. Use $Timezones for a full list of timezones I can convert from CEST." await message.channel.send(response.format(message)) return tzdesthours = tzdestination["Hours"] tzdestminutes = tzdestination["Minutes"] tzdestname = tzdestination["Name"] tzsourcehours = tzsource["Hours"] tzsourceminutes = tzsource["Minutes"] tzsourcename = tzsource["Name"] newhours = int(hours) - tzsourcehours + tzdesthours newminutes = int(minutes) - tzsourceminutes + tzdestminutes day = "" if newminutes > 59: newminutes = newminutes - 30 newhours = newhours + 1 elif newminutes < 0: newminutes = newminutes + 30 newhours = newhours - 1 if newhours > 23: newhours = newhours - 24 day = " (+1 day)" elif newhours < 0: newhours = newhours + 24 day = " (-1 day)" response = time + " " + sourcetz + " (" + tzsourcename + ") is " + ( "00" + str(newhours))[-2:] + ":" + ( "00" + str(newminutes) )[-2:] + " " + desttz + " (" + tzdestname + ")" + day + "." await message.channel.send(response.format(message)) else: response = "Invalid Time format. Must be in format `hh:mm`." await message.channel.send(response.format(message)) return if message.content.lower() == ("$roll"): await utility.roll(client, message) return if message.content.lower().startswith("$roll "): await utility.rolls(client, message) return if message.content.lower() == ("$quantumroll"): await utility.quantumroll(client, message) return if message.content.lower().startswith("$quantumroll "): await utility.quantumrolls(client, message) return if message.content.lower() == ("$flip"): i = random.randint(0, 1) if i == 0: response = "It's Heads!" else: response = "It's Tails!" await message.channel.send(response.format(message)) return #Timer commands if message.content.lower() == "$timer": await message.channel.send( "The $timer command must be followed by a time period, and optionally a reason. For example: `$timer 03:00` will set a timer for 3 hours. If you wish, you can include a reason afterwards. For example: `$timer 01:30 Ryan and Thom's game` will set a timer for 1 hour 30 minutes with the reason *\"Ryan and Thom's game\"*." ) return if message.content.lower().startswith("$timer "): timer = message.content[7:12] hours = message.content[7:9] minutes = message.content[10:12] seconds = "00" reason = message.clean_content[13:] if re.match("[0-9][0-9]:[0-5][0-9]", timer): response = "Setting timer for " + str( int(hours)) + " hour(s) and " + str( int(minutes)) + " minute(s). Let the count down begin!" await message.channel.send(response.format(message)) duration = int(seconds) + (int(minutes) * 60) + (int(hours) * 60 * 60) now = datetime.utcnow() embed = discord.Embed(title="Timer", description=reason, color=0x4444dd) embed.add_field(name="Duration", value="`" + '%02d' % int(hours) + ":" + '%02d' % int(minutes) + ":" + '%02d' % int(seconds) + "` ", inline=True) embed.add_field(name="Remaining", value="`" + '%02d' % int(hours) + ":" + '%02d' % int(minutes) + ":" + '%02d' % int(seconds) + "` ", inline=True) embed.set_footer(text="Updated at: " + now.strftime("%Y-%m-%d %H:%M:%S") + " UTC") timermsg = await message.channel.send(embed=embed) #Start counting down start = datetime.now() end = start + timedelta(seconds=duration) i = 0 import time while datetime.now() < end: time.sleep(0.5) i = i + 1 remaining = int((end - datetime.now()).total_seconds()) hours = str(int(remaining / 3600)) minutes = str(int((remaining % 3600) / 60)) seconds = str(remaining % 60) if (remaining >= 600 and i == 30) or ( remaining >= 30 and remaining < 600 and i >= 10) or (remaining < 30 and i >= 5) or remaining <= 5: now = datetime.utcnow() embed.set_field_at(1, name="Remaining", value="`" + '%02d' % int(hours) + ":" + '%02d' % int(minutes) + ":" + '%02d' % int(seconds) + "` ", inline=True) embed.set_footer(text="Updated at: " + now.strftime("%Y-%m-%d %H:%M:%S") + " UTC") await timermsg.edit(embed=embed) i = 0 #timer complete! embed.set_field_at(1, name="Remaining", value="`00:00:00` ", inline=True) await timermsg.edit(embed=embed) response = "Your timer has finished {0.author.mention}!".format( message) await message.channel.send(response) else: await message.channel.send("That isn't a valid time!") return if message.content.lower() == "$heret": response = "The $heret command must be followed by a time period and a reason. For example: `$heret 03:00 dice down` will set a timer for 3 hours the reason *\"dice down\"*." await message.channel.send(response.format(message)) return if message.content.lower().startswith("$heret "): timer = message.content[7:12] hours = message.content[7:9] minutes = message.content[10:12] seconds = "00" reason = message.content[13:] if reason == "": await message.channel.send("Here timers must have a reason.") return if access.isowner(message.guild, message.author) or access.isadmin( message.guild, message.author) or access.isheadjudge( message.guild, message.author): if re.match("[0-9][0-9]:[0-5][0-9]", timer): response = "Setting timer for " + str( int(hours)) + " hour(s) and " + str( int(minutes)) + " minute(s). Let the count down begin!" await message.channel.send(response.format(message)) duration = int(seconds) + (int(minutes) * 60) + (int(hours) * 60 * 60) now = datetime.utcnow() embed = discord.Embed(title="Here Timer", description=reason, color=0x4444dd) embed.add_field(name="Duration", value="`" + '%02d' % int(hours) + ":" + '%02d' % int(minutes) + ":" + '%02d' % int(seconds) + "` ", inline=True) embed.add_field(name="Remaining", value="`" + '%02d' % int(hours) + ":" + '%02d' % int(minutes) + ":" + '%02d' % int(seconds) + "` ", inline=True) embed.set_footer(text="Updated at: " + now.strftime("%Y-%m-%d %H:%M:%S") + " UTC") timermsg = await message.channel.send(embed=embed) #Start counting down start = datetime.now() end = start + timedelta(seconds=duration) i = 0 import time while datetime.now() < end: i = i + 1 time.sleep(0.5) remaining = int((end - datetime.now()).total_seconds()) hours = str(int(remaining / 3600)) minutes = str(int((remaining % 3600) / 60)) seconds = str(remaining % 60) if (remaining >= 600 and i == 30) or ( remaining >= 30 and remaining < 600 and i >= 10) or (remaining < 30 and i >= 5) or remaining <= 5: now = datetime.utcnow() embed.set_field_at(1, name="Remaining", value="`" + '%02d' % int(hours) + ":" + '%02d' % int(minutes) + ":" + '%02d' % int(seconds) + "` ", inline=True) embed.set_footer(text="Updated at: " + now.strftime("%Y-%m-%d %H:%M:%S") + " UTC") await timermsg.edit(embed=embed) i = 0 #timer complete! embed.set_field_at(1, name="Remaining", value="`00:00:00`", inline=True) await timermsg.edit(embed=embed) response = "".join( ["@here , the timer has finished! ", reason]).format(message) await message.channel.send(response) else: await message.channel.send("That isn't a valid time!") else: await message.channel.send( "You must be a Judge to use Here Timers.") return if message.content.lower().startswith("$germanpairing"): if str(message.channel).lower().startswith("table"): if len(message.mentions) == 1: await pairings.german(client, message) else: response = "You must mention your opponent to begin a pairing process." await message.channel.send(response.format(message)) else: response = "You can only use this command in a table channel." await message.channel.send(response.format(message)) return if message.content.lower() == "$loscheck": if str(message.channel).lower().startswith("table"): await utility.loscheck(client, message) return if message.content.lower().startswith("$redeem"): if "table" in str(message.channel).lower() or str( message.channel).lower().startswith("bot"): await redeem.redeempurchase(client, message) else: response = "You can only use this command in a table or bot channel." await message.channel.send(response.format(message)) return if message.content.lower() == "$events": await events.events(message) return if message.content.lower().startswith("$eventdetails"): if not (message.content[14:].isdecimal()): response = "Invalid event ID." await message.channel.send(response.format(message)) return await events.eventdetails(message, message.content[14:]) return #Want these commands in the right channel if str(message.channel).lower().startswith("bot"): if message.content.lower().startswith("$addroleaccess"): await access.addaccess(client, message) return if message.content.lower().startswith("$removeroleaccess"): await access.removeaccess(message) return if message.content.lower().startswith("$checkroleaccess"): await access.checkaccess(message) return if message.content.lower() == "$colours": response = "You can choose from any of the following colours: *" + ", ".join( colours ) + "*. Alternatively you can use *random* for a random colour, or provide your own 6 digit hex code." await message.channel.send(response.format(message)) return if message.content.lower().startswith("$addcaptain"): await teams.addcaptain(message) return if message.content.lower().startswith("$addeventdetail"): await events.adddetail(client, message) return if message.content.lower().startswith("$addevent"): await events.addevent(client, message) return if message.content.lower().startswith("$editevent"): await events.editevent(client, message) return if message.content.lower().startswith("$deleteevent"): await events.deleteevent(client, message) return if message.content.lower().startswith("$deletedetail"): await events.deletedetail(client, message) return if message.content.lower().startswith("$createteam"): await teams.createteam(message) return if message.content.lower().startswith("$registerteam"): await teams.registerteam(client, message) return if message.content.lower().startswith("$deregisterteam"): await teams.deregisterteam(client, message) return if message.content.lower().startswith("$addplayer"): await teams.addplayer(client, message) return if message.content.lower().startswith("$removeplayer"): await teams.removeplayer(client, message) return if message.content.lower().startswith("$teamcolour"): await teams.changecolour(client, message) return if message.content.lower().startswith("$renameteam"): await teams.renameteam(client, message) return if message.content.lower() == "$deleteteam": await teams.deleteteam(client, message) return if message.content.lower() == "$leaveteam": await teams.leaveteam(client, message) return if message.content.lower().startswith("$assigncaptain"): await teams.assigncaptain(client, message) return if message.content.lower().startswith("$removecaptain"): await teams.removecaptain(client, message) return if message.content.lower() == "$fetchscores": await games.fetchhiscores(message) return if not (debugon is None): print('Random Number is:' + str(rng)) if (rng % 50 == 0 or (message.channel.name.lower().startswith('bot') and message.content.lower() == 'play fetch') ) and not (message.content.lower() == 'play tug of war'): print("Playing Fetch Game") await games.playfetch(client, message) if ((rng % 25 == 0 and not (rng % 50 == 0)) or (message.channel.name.lower().startswith('bot') and message.content.lower() == 'play tug of war') ) and not (message.content.lower() == 'play fetch'): #await games.playtugofwar(client,message) print("Tug of War Game Disabled") #Adhoc Commands. Only work in Debug Mode if not (debugon is None) and message.content.lower() == "$synctables": await adhoc.synctables(message) return if not (debugon is None) and message.content.lower().startswith("$purgeroles"): await adhoc.purgeroles(message) return