async def yews(self, ctx): ''' Returns the time until the next divine yews event. ''' addCommand() now = datetime.utcnow() now = now.replace(microsecond=0) msg = config[ 'yewsEmoji'] + " **Divine yews** will begin in " + timeDiffToString( self.bot.next_yews48 - now) + " in w48 bu, and in " + timeDiffToString( self.bot.next_yews140 - now) + " in w140 bu." await ctx.send(msg)
async def vos(self, ctx): ''' Returns the current Voice of Seren. ''' addCommand() now = datetime.utcnow() now = now.replace(second=0, microsecond=0) time_to_vos = self.bot.next_vos - now time_to_vos = timeDiffToString(time_to_vos) current = self.bot.vos['vos'] next_vos = self.bot.vos['next'] emoji0 = config[current[0].lower() + 'Emoji'] emoji1 = config[current[1].lower() + 'Emoji'] current_txt = f'{emoji0} {current[0]}\n{emoji1} {current[1]}' next_txt = f'{next_vos[0]}, {next_vos[1]}, {next_vos[2]}, {next_vos[3]}' title = f'Voice of Seren' colour = 0x00b2ff embed = discord.Embed(title=title, colour=colour, description=current_txt) embed.add_field(name=f'Up next ({time_to_vos})', value=next_txt, inline=False) await ctx.send(embed=embed)
async def sinkhole(self, ctx): ''' Returns the time until the next sinkhole. ''' addCommand() now = datetime.utcnow() now = now.replace(microsecond=0) msg = config[ 'sinkholeEmoji'] + " **Sinkhole** will spawn in " + timeDiffToString( self.bot.next_sinkhole - now) + "." await ctx.send(msg)
async def goebies(self, ctx): ''' Returns the time until the next goebies supply run. ''' addCommand() now = datetime.utcnow() now = now.replace(microsecond=0) msg = config[ 'goebiesEmoji'] + " **Goebies supply run** will begin in " + timeDiffToString( self.bot.next_goebies - now) + "." await ctx.send(msg)
async def cache(self, ctx): ''' Returns the time until the next Guthixian cache. ''' addCommand() now = datetime.utcnow() now = now.replace(microsecond=0) msg = config[ 'cacheEmoji'] + " **Guthixian caches** will begin in " + timeDiffToString( self.bot.next_cache - now) + "." await ctx.send(msg)
async def warbands(self, ctx): ''' Returns the time until wilderness warbands starts. ''' addCommand() now = datetime.utcnow() now = now.replace(microsecond=0) msg = config[ 'warbandsEmoji'] + " **Wilderness warbands** will begin in " + timeDiffToString( self.bot.next_warband - now) + "." await ctx.send(msg)
async def spotlight(self, ctx): ''' Returns the current and next minigame spotlight. ''' addCommand() now = datetime.utcnow() now = now.replace(microsecond=0) embed = discord.Embed(title='Minigame Spotlight', colour=0x00b2ff, description=self.bot.spotlight) embed.set_footer(text=timeDiffToString(self.bot.next_spotlight - now)) await ctx.send(embed=embed)
async def timer(self, ctx, time='', unit='', *msg): ''' Lets the user set a timer. Arguments: time, unit (optional, default m), message (optional). Constraints: time can range from 1 s to 24 h. Unit can be s, m, h. Please note that timers will be lost if the bot is restarted or goes down unexpectedly. Don't forget to surround your inputs with "quotation marks" if they contains spaces. ''' addCommand() if not time: raise commands.CommandError( message=f'Required argument missing: `time`.') count = time.count(':') if count: if count == 1: index = time.index(':') h = time[:index] m = time[index + 1:] if not is_int(h) or not is_int(m): raise commands.CommandError( message=f'Invalid argument: time `{time}`.') else: time = int(h) * 3600 + int(m) * 60 if time % 3600 == 0: unit = 'hours' else: unit = 'minutes' elif count == 2: index = time.index(':') h = time[:index] time = time[index + 1:] index = time.index(':') m = time[:index] s = time[index + 1:] if not is_int(h) or not is_int(m) or not is_int(s): raise commands.CommandError( message=f'Invalid argument: time `{time}`.') else: time = int(h) * 3600 + int(m) * 60 + int(s) if time % 60 == 0: unit = 'minutes' elif time % 3600 == 0: unit = 'hours' else: unit = 'seconds' elif is_int(time): time = int(time) else: raise commands.CommandError( message=f'Invalid argument: time `{time}`.') if not count: if unit: if 'S' in unit.upper(): unit = 'seconds' elif 'M' in unit.upper(): unit = 'minutes' time *= 60 elif 'H' in unit.upper(): unit = 'hours' time *= 3600 else: unit = 'minutes' time *= 60 if time < 1 or time > 86400: raise commands.CommandError( message=f'Invalid argument: time `{time}`.') timeStr = timeDiffToString(timedelta(seconds=time)) await ctx.send(f'You have set a timer for **{timeStr}**.') await asyncio.sleep(time) if msg: txt = '' for i in msg: txt += i + ' ' txt = txt.strip() await ctx.send(f'{ctx.author.mention} {txt}') else: await ctx.send(f'{ctx.author.mention} It\'s time!')