Skip to content

Commit

Permalink
Cleaning code
Browse files Browse the repository at this point in the history
  • Loading branch information
geirawsm committed Sep 13, 2024
1 parent 96c1baf commit e1c1155
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 31 deletions.
16 changes: 4 additions & 12 deletions sausage_bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ async def on_ready():
}
channel_out = await guild.create_text_channel(
name=str(bot_channel),
topic=I18N.t('main.msg.create_log_channel_logging', botname=config.bot.user.name),
topic=I18N.t(
'main.msg.create_log_channel_logging',
botname=config.bot.user.name
),
overwrites=overwrites
)
channel_out.set_permissions()
Expand Down Expand Up @@ -496,17 +499,6 @@ async def language(
return


@commands.check_any(commands.is_owner())
@config.bot.tree.command(
name='test', description=locale_str(I18N.t('main.owner_only'))
)
async def test(interaction: discord.Interaction):
await interaction.response.send_message(
I18N.t('dilemmas.commands.count.msg_confirm', count=0),
ephemeral=True
)
return


try:
config.bot.run(config.DISCORD_TOKEN)
Expand Down
37 changes: 20 additions & 17 deletions sausage_bot/cogs/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async def stats_posting_start(
):
await interaction.response.defer(ephemeral=True)
log.log(I18N.t('stats.commands.start.log_started'))
Stats.update_stats.start()
Stats.task_update_stats.start()
await db_helper.update_fields(
template_info=envs.tasks_db_schema,
where=[
Expand All @@ -152,7 +152,7 @@ async def stats_posting_stop(
):
await interaction.response.defer(ephemeral=True)
log.log(I18N.t('stats.commands.stop.log_stopped'))
Stats.update_stats.cancel()
Stats.task_update_stats.cancel()
await db_helper.update_fields(
template_info=envs.tasks_db_schema,
where=[
Expand Down Expand Up @@ -186,7 +186,7 @@ async def stats_posting_restart(
):
await interaction.response.defer(ephemeral=True)
log.log('Stats posting restarted')
Stats.update_stats.restart()
Stats.task_update_stats.restart()
await interaction.followup.send(
I18N.t('commands.restart.log_restarted')
)
Expand Down Expand Up @@ -256,7 +256,9 @@ async def list_settings(
)
@stats_settings_group.command(
name='change',
description=locale_str(I18N.t('stats.commands.settings.change.command'))
description=locale_str(
I18N.t('stats.commands.settings.change.command')
)
)
async def stats_setting(
self, interaction: discord.Interaction, name_of_setting: str,
Expand Down Expand Up @@ -300,7 +302,7 @@ async def stats_setting(
content=I18N.t('stats.commands.setting.update_confirmed'),
ephemeral=True
)
Stats.update_stats.restart()
Stats.task_update_stats.restart()
break
return

Expand Down Expand Up @@ -336,7 +338,7 @@ async def add_setting(
content=I18N.t('stats.commands.add.add_confirmed'),
ephemeral=True
)
Stats.update_stats.restart()
Stats.task_update_stats.restart()
return

@commands.check_any(
Expand Down Expand Up @@ -386,7 +388,7 @@ async def stats_add_hidden_roles(
'stats.commands.hide_roles_add.msg.confirm_added'),
ephemeral=True
)
Stats.update_stats.restart()
Stats.task_update_stats.restart()
return

@commands.check_any(
Expand Down Expand Up @@ -423,7 +425,7 @@ async def stats_remove_hidden_roles(
'stats.commands.hide_roles_remove.msg.confirm_removed'),
ephemeral=True
)
Stats.update_stats.restart()
Stats.task_update_stats.restart()
return

@commands.check_any(
Expand All @@ -439,7 +441,7 @@ async def stats_restart(
):
'''Restart the stats task'''
await interaction.response.defer(ephemeral=True)
Stats.update_stats.restart()
Stats.task_update_stats.restart()
await interaction.followup.send(
content=I18N.t('stats.commands.restart.msg.confirm_restarted'),
ephemeral=True
Expand All @@ -450,7 +452,7 @@ async def stats_restart(
@tasks.loop(
minutes=config.env.int('STATS_LOOP', default=5)
)
async def update_stats():
async def task_update_stats():
'''
Update interesting stats in a channel post and write the info to
the log db.
Expand Down Expand Up @@ -635,15 +637,16 @@ async def tabify(
stats_info += f'```{code_last_updated} {dt_log}```\n'
log.verbose(
f'Trying to post stats to `{stats_channel}`:\n'
f'{stats_info[0:100]}...'
)
_guild = discord_commands.get_guild()
f'{stats_infonrd_commands.get_guild()
stats_msg_id = stats_settings['stats_msg']
stats_channel = get(_guild.channels, name=stats_channel)
log.verbose(
f'Got `stats_channel` {stats_channel} ({type(stats_channel)})'
)
if stats_msg_id == '':
log.verbose(
'`stats_msg` not found in database, creating new stats message'
)
stats_msg = await stats_channel.send(stats_info)
await db_helper.update_fields(
template_info=envs.stats_db_settings_schema,
Expand Down Expand Up @@ -681,7 +684,7 @@ async def tabify(
log.error('Could not find stats_msg_id')
return

@update_stats.before_loop
@task_update_stats.before_loop
async def before_update_stats():
'#autodoc skip#'
log.verbose('`update_stats` waiting for bot to be ready...')
Expand Down Expand Up @@ -763,11 +766,11 @@ async def setup(bot):
if task[0] == 'post_stats':
if task[1] == 'started':
log.debug(f'`{task[0]}` is set as `{task[1]}`, starting...')
Stats.update_stats.start()
Stats.task_update_stats.start()
elif task[1] == 'stopped':
log.debug(f'`{task[0]}` is set as `{task[1]}`')
Stats.update_stats.cancel()
Stats.task_update_stats.cancel()


async def teardown(bot):
Stats.update_stats.cancel()
Stats.task_update_stats.cancel()
3 changes: 1 addition & 2 deletions sausage_bot/util/discord_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ async def get_message_obj(
Parameters
------------
msg_id: int/str
The message ID to look for, or name of the saved message in
settings file
The message ID to look for
channel: str
Channel to get message from (default: None)
'''
Expand Down

0 comments on commit e1c1155

Please sign in to comment.