remind: add cooldowns; also add botlog channel

This commit is contained in:
Ave Ozkal 2018-12-31 02:05:40 +03:00
parent c79093eb57
commit 203761856e
No known key found for this signature in database
GPG key ID: 09356ABAA42C842B
4 changed files with 18 additions and 10 deletions

View file

@ -83,19 +83,19 @@ async def on_ready():
aioh = {"User-Agent": f"{script_name}/1.0'"} aioh = {"User-Agent": f"{script_name}/1.0'"}
bot.aiosession = aiohttp.ClientSession(headers=aioh) bot.aiosession = aiohttp.ClientSession(headers=aioh)
bot.app_info = await bot.application_info() bot.app_info = await bot.application_info()
bot.botlog_channel = bot.get_channel(config.botlog_channel)
log.info(f'\nLogged in as: {bot.user.name} - ' log.info(f'\nLogged in as: {bot.user.name} - '
f'{bot.user.id}\ndpy version: {discord.__version__}\n') f'{bot.user.id}\ndpy version: {discord.__version__}\n')
game_name = f"{config.prefixes[0]}help" game_name = f"{config.prefixes[0]}help"
# Send "Robocop has started! x has y members!" # Send "Robocop has started! x has y members!"
log_channel = bot.get_channel(config.log_channel) guild = bot.botlog_channel.guild
guild = log_channel.guild
msg = f"{bot.user.name} has started! "\ msg = f"{bot.user.name} has started! "\
f"{guild.name} has {guild.member_count} members!" f"{guild.name} has {guild.member_count} members!"
data_files = [discord.File(fpath) for fpath in wanted_jsons] data_files = [discord.File(fpath) for fpath in wanted_jsons]
await log_channel.send(msg, files=data_files) await bot.botlog_channel.send(msg, files=data_files)
await bot.change_presence(activity=discord.Game(name=game_name)) await bot.change_presence(activity=discord.Game(name=game_name))
@ -121,9 +121,13 @@ async def on_error(event_method, *args, **kwargs):
async def on_command_error(ctx, error): async def on_command_error(ctx, error):
error_text = str(error) error_text = str(error)
log.error(f"Error with \"{ctx.message.content}\" from " err_msg = f"Error with \"{ctx.message.content}\" from "\
f"\"{ctx.message.author} ({ctx.message.author.id}) " f"\"{ctx.message.author} ({ctx.message.author.id}) "\
f"of type {type(error)}: {error_text}") f"of type {type(error)}: {error_text}"
log.error(err_msg)
await bot.botlog_channel.send(err_msg)
if isinstance(error, commands.NoPrivateMessage): if isinstance(error, commands.NoPrivateMessage):
return await ctx.send("This command doesn't work on DMs.") return await ctx.send("This command doesn't work on DMs.")

View file

@ -10,6 +10,7 @@ class Remind:
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
@commands.cooldown(1, 60, type=commands.BucketType.user)
@commands.command() @commands.command()
async def remindlist(self, ctx): async def remindlist(self, ctx):
"""Lists your reminders.""" """Lists your reminders."""
@ -25,6 +26,7 @@ class Remind:
inline=False) inline=False)
await ctx.send(embed=embed) await ctx.send(embed=embed)
@commands.cooldown(1, 60, type=commands.BucketType.user)
@commands.command() @commands.command()
async def remind(self, ctx, when: str, *, text: str = "something"): async def remind(self, ctx, when: str, *, text: str = "something"):
"""Reminds you about something.""" """Reminds you about something."""
@ -37,6 +39,7 @@ class Remind:
"remind interval is 5 seconds.") "remind interval is 5 seconds.")
await asyncio.sleep(5) await asyncio.sleep(5)
await msg.delete() await msg.delete()
return
expiry_datetime = datetime.utcfromtimestamp(expiry_timestamp) expiry_datetime = datetime.utcfromtimestamp(expiry_timestamp)
duration_text = self.bot.get_relative_timestamp(time_to=expiry_datetime, duration_text = self.bot.get_relative_timestamp(time_to=expiry_datetime,

View file

@ -17,7 +17,7 @@ class Robocronp:
async def send_data(self): async def send_data(self):
data_files = [discord.File(fpath) for fpath in self.bot.wanted_jsons] data_files = [discord.File(fpath) for fpath in self.bot.wanted_jsons]
log_channel = self.bot.get_channel(config.log_channel) log_channel = self.bot.get_channel(config.botlog_channel)
await log_channel.send("Hourly data backups:", files=data_files) await log_channel.send("Hourly data backups:", files=data_files)
@commands.guild_only() @commands.guild_only()
@ -54,7 +54,7 @@ class Robocronp:
await ctx.send(f"{ctx.author.mention}: Deleted!") await ctx.send(f"{ctx.author.mention}: Deleted!")
async def do_jobs(self, ctab, jobtype, timestamp): async def do_jobs(self, ctab, jobtype, timestamp):
log_channel = self.bot.get_channel(config.log_channel) log_channel = self.bot.get_channel(config.botlog_channel)
for job_name in ctab[jobtype][timestamp]: for job_name in ctab[jobtype][timestamp]:
try: try:
job_details = ctab[jobtype][timestamp][job_name] job_details = ctab[jobtype][timestamp][job_name]
@ -90,7 +90,7 @@ class Robocronp:
async def minutely(self): async def minutely(self):
await self.bot.wait_until_ready() await self.bot.wait_until_ready()
log_channel = self.bot.get_channel(config.log_channel) log_channel = self.bot.get_channel(config.botlog_channel)
while not self.bot.is_closed(): while not self.bot.is_closed():
try: try:
ctab = get_crontab() ctab = get_crontab()
@ -107,7 +107,7 @@ class Robocronp:
async def hourly(self): async def hourly(self):
await self.bot.wait_until_ready() await self.bot.wait_until_ready()
log_channel = self.bot.get_channel(config.log_channel) log_channel = self.bot.get_channel(config.botlog_channel)
while not self.bot.is_closed(): while not self.bot.is_closed():
# Your stuff that should run at boot # Your stuff that should run at boot
# and after that every hour goes here # and after that every hour goes here

View file

@ -37,6 +37,7 @@ staff_role_ids = [526384077679624192, # Team role in NotSwitched
526383985430102016] # Wizard role in NotSwitched 526383985430102016] # Wizard role in NotSwitched
log_channel = 526377735908491284 # Log channel in NotSwitched log_channel = 526377735908491284 # Log channel in NotSwitched
botlog_channel = 529070401704296460 # Botlog channel in NotSwitched
welcome_channel = 526372470752673792 # rules-info channel in NotSwitched welcome_channel = 526372470752673792 # rules-info channel in NotSwitched
community_channels = [526378423468425236] # Channels requiring community role community_channels = [526378423468425236] # Channels requiring community role