Skip to content

Commit

Permalink
db_helper.get_output outputs dict, started updating code
Browse files Browse the repository at this point in the history
  • Loading branch information
geirawsm committed Dec 14, 2024
1 parent 7db95f7 commit 383cd93
Show file tree
Hide file tree
Showing 12 changed files with 291 additions and 221 deletions.
6 changes: 4 additions & 2 deletions sausage_bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ async def on_ready():
single=True
)
log.debug(f'Setting locale to `{locale_db}`')
I18N.set('locale', locale_db)
I18N.set('locale', locale_db['locale'])
await config.bot.tree.set_translator(MyTranslator())
for guild in config.bot.guilds:
if guild.name == config.env('DISCORD_GUILD'):
Expand Down Expand Up @@ -609,7 +609,9 @@ async def get_tasks_list(interaction: discord.Interaction):
log.debug(f'Got this from `tasks_in_db`: {tasks_in_db}')
text_out = '```{}```'.format(
tabulate(
tasks_in_db, headers=['Cog', 'Task', 'Status']
tasks_in_db, headers={
'cog': 'Cog', 'task': 'Task', 'status': 'Status'
}
)
)
log.debug(f'Returning:\n{text_out}')
Expand Down
52 changes: 35 additions & 17 deletions sausage_bot/cogs/log_maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ async def name_of_settings_autocomplete(
)
settings = []
for setting in db_settings:
settings.append((setting[0], setting[1]))
settings.append((setting['setting'], setting['value']))
log.debug(f'settings: {settings}')
return [
discord.app_commands.Choice(
name=f'{setting[0]} ({setting[1]})', value=str(setting[0])
name='{} ({})'.format(
setting['setting'], setting['value']
), value=str(setting['setting'])
)
for setting in settings if current.lower() in setting[0].lower()
for setting in settings if current.lower() in
setting['setting'].lower()
]


Expand Down Expand Up @@ -120,11 +123,13 @@ async def list_settings(
template_info=envs.log_db_schema,
select=('setting', 'value', 'value_help')
)
headers = [
I18N.t('log_maintenance.commands.list.headers.setting'),
I18N.t('log_maintenance.commands.list.headers.value'),
I18N.t('log_maintenance.commands.list.headers.value_type')
]
headers = {
'setting': I18N.t('log_maintenance.commands.list.headers.setting'),
'value': I18N.t('log_maintenance.commands.list.headers.value'),
'value_help': I18N.t(
'log_maintenance.commands.list.headers.value_type'
)
}
await interaction.followup.send(
content='```{}```'.format(
tabulate(settings_in_db, headers=headers)
Expand Down Expand Up @@ -162,8 +167,8 @@ async def log_setting(
select=('setting', 'value', 'value_check')
)
for setting in settings_in_db:
if setting[0] == name_of_setting:
if setting[2] == 'bool':
if setting['setting'] == name_of_setting:
if setting['value_check'] == 'bool':
try:
value_in = eval(str(value_in).capitalize())
except NameError as _error:
Expand All @@ -177,8 +182,13 @@ async def log_setting(
)
return
log.debug(f'`value_in` is {value_in} ({type(value_in)})')
log.debug(f'`setting[2]` is {setting[2]} ({type(setting[2])})')
if type(value_in) is eval(setting[2]):
log.debug(
'`setting[\'value_check\']` is {} ({})'.format(
setting['value_check'],
type(setting['value_check'])
)
)
if type(value_in) is eval(setting['value_check']):
await db_helper.update_fields(
template_info=envs.log_db_schema,
where=[('setting', name_of_setting)],
Expand Down Expand Up @@ -333,10 +343,18 @@ async def setup(bot):
)
log.verbose(f'Got `task_list`: {task_list}')
for task in task_list:
if task[0] == 'log_maintenance':
if task[1] == 'started':
log.debug(f'`{task[0]}` is set as `{task[1]}`, starting...')
if task['task'] == 'log_maintenance':
if task['status'] == 'started':
log.debug(
'`{task}` is set as `{status}`, starting...'.format(
task=task['task'], status=task['status']
)
)
LogMaintenance.log_maintenance.start()
elif task[1] == 'stopped':
log.debug(f'`{task[0]}` is set as `{task[1]}`')
elif task['status'] == 'stopped':
log.debug(
'`{task}` is set as `{status}`'.format(
task=task['task'], status=task['status']
)
)
LogMaintenance.log_maintenance.cancel()
4 changes: 3 additions & 1 deletion sausage_bot/cogs/poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ async def poll(
# Move reaction to the text
desc_out = f'{poll_text}\n'
for reaction in sorted_reacts:
desc_out += f'\n{reaction[0]}: {reaction[1]}'
desc_out += '\n{}: {}'.format(
reaction['input'], reaction['count']
)
embed_json = discord.Embed.from_dict(
{
'title': I18N.t('poll.commands.poll.msg.embed_title'),
Expand Down
10 changes: 5 additions & 5 deletions sausage_bot/cogs/quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ async def prep_quotes(
)
log.debug('Got quotes: {}'.format(quote_in))
for _q in quote_in:
q_no = _q[0]
q_no = _q['rowid']
if any(item is None for item in _q):
log.error(
f'None-values discovered in DB-file (quotes): {_q}'
Expand All @@ -620,11 +620,11 @@ async def prep_quotes(
else:
if shortened:
q_text = '{}...'.format(
_q[2][0:100]
) if len(_q[2]) > 100 else _q[2]
_q['quote_text'][0:100]
) if len(_q['quote_text']) > 100 else _q['quote_text']
else:
q_text = _q[2]
q_datetime = _q[3]
q_text = _q['quote_text']
q_datetime = _q['datetime']
quotes_out.append(
(
q_no, q_text, q_datetime
Expand Down
Loading

0 comments on commit 383cd93

Please sign in to comment.