Skip to content

Commit

Permalink
Cleaning code
Browse files Browse the repository at this point in the history
  • Loading branch information
geirawsm committed Aug 26, 2024
1 parent f7a0920 commit fab54b0
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 27 deletions.
4 changes: 3 additions & 1 deletion sausage_bot/cogs/autoevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ async def event_add(
ephemeral=True
)
except (discord.HTTPException) as e:
log.error(envs.AUTOEVENT_HTTP_EXCEPTION_ERROR.format(e.text))
log.error(
envs.AUTOEVENT_HTTP_EXCEPTION_ERROR.format(e.text)
)
if 'Cannot schedule event in the past' in str(e):
log.log(envs.AUTOEVENT_EVENT_START_IN_PAST)
# Delete command message
Expand Down
6 changes: 2 additions & 4 deletions sausage_bot/cogs/quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# -*- coding: UTF-8 -*-
import discord
from discord.ext import commands
from discord.utils import get
import typing
import uuid
from asyncio import TimeoutError

Expand Down Expand Up @@ -177,7 +175,7 @@ async def on_submit(self, interaction: discord.Interaction):

await interaction.response.send_message(
# TODO i18n
f'Quote added', ephemeral=True
'Quote added', ephemeral=True
)

async def on_error(self, interaction: discord.Interaction, error):
Expand Down Expand Up @@ -230,7 +228,7 @@ async def on_submit(self, interaction: discord.Interaction):

await interaction.response.send_message(
# TODO i18n
f'Quote edited', ephemeral=True
'Quote edited', ephemeral=True
)

async def on_error(self, interaction: discord.Interaction, error):
Expand Down
14 changes: 8 additions & 6 deletions sausage_bot/cogs/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ async def settings_autocomplete(
),
value=str(setting[0])
)
for setting in settings_in_list if current.lower() in setting[3].lower()
for setting in settings_in_list
if current.lower() in setting[3].lower()
]


Expand Down Expand Up @@ -283,7 +284,6 @@ async def sync_reaction_message_from_settings(
}
# Edit discord message
await msg_obj.edit(
#content=db_message[0][3],
embed=discord.Embed.from_dict(embed_json)
)
return
Expand Down Expand Up @@ -1533,7 +1533,7 @@ async def add_settings(
]
)
# TODO i18n
await interaction.followup.send(f'Added setting')
await interaction.followup.send('Added setting')
return

@commands.check_any(
Expand Down Expand Up @@ -1563,15 +1563,15 @@ async def remove_settings(
numbers=setting
)
# TODO i18n
await interaction.followup.send(f'Removed setting')
await interaction.followup.send('Removed setting')
return

@commands.check_any(
commands.is_owner(),
commands.has_permissions(manage_roles=True)
)
@roles_settings_group.command(
name='list', description='List settings for roles on the server'
name='list', description='List settings for roles on the server'
)
async def list_settings(
self, interaction: discord.Interaction
Expand All @@ -1593,7 +1593,9 @@ async def list_settings(
_settings_db_expanded.append(
(setting[0], _role, setting[1])
)
_settings = tabulate(_settings_db_expanded, headers=['Setting', 'Role', 'Value'])
_settings = tabulate(
_settings_db_expanded, headers=['Setting', 'Role', 'Value']
)
# TODO i18n
await interaction.followup.send(f'```{_settings}```')
return
Expand Down
9 changes: 6 additions & 3 deletions sausage_bot/cogs/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ async def hidden_roles_autocomplete(
interaction: discord.Interaction,
current: str,
) -> list[discord.app_commands.Choice[str]]:

hidden_roles_in_db = await db_helper.get_output(
template_info=envs.stats_db_hide_roles_schema,
get_row_ids=True
Expand Down Expand Up @@ -445,8 +444,12 @@ async def tabify(
if role != '@everyone':
# Check for `sort_min_role_members`
if stats_settings['sort_min_role_members']:
min_members = stats_settings['sort_min_role_members']
if dict_in[role]['members'] >= int(min_members):
min_members = stats_settings[
'sort_min_role_members'
]
if dict_in[role]['members'] >= int(
min_members
):
dict_out['name'].append(
dict_in[role]['name'])
dict_out['members'].append(
Expand Down
6 changes: 4 additions & 2 deletions sausage_bot/cogs/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,13 @@ async def setup(bot):
)
youtube_filter_prep_is_ok = await db_helper.prep_table(
envs.youtube_db_filter_schema,
youtube_inserts['filter'] if youtube_inserts is not None else youtube_inserts
youtube_inserts['filter']
if youtube_inserts is not None else youtube_inserts
)
youtube_log_prep_is_ok = await db_helper.prep_table(
envs.youtube_db_log_schema,
youtube_inserts['logs'] if youtube_inserts is not None else youtube_inserts
youtube_inserts['logs']
if youtube_inserts is not None else youtube_inserts
)
log.verbose(f'`youtube_prep_is_ok` is {youtube_prep_is_ok}')
log.verbose(
Expand Down
4 changes: 3 additions & 1 deletion sausage_bot/util/discord_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ async def remove_stats_post(stats_channel):
if str(msg.author.id) == config.BOT_ID:
if 'Serverstats sist' in str(msg.content):
# TODO var msg
log.debug('Found post with `Serverstats sist`, removing...')
log.debug(
'Found post with `Serverstats sist`, removing...'
)
await msg.delete()
found_stats_msg = True
return
Expand Down
12 changes: 6 additions & 6 deletions sausage_bot/util/feeds_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ async def add_to_feed_db(
test_link = await net_io.get_link(feed_link)
if not args.rss_skip_url_validation:
if test_link is None:
log.verbose(f'`test_link` is None')
log.verbose('`test_link` is None')
return None
elif isinstance(test_link, int):
log.verbose(f'`test_link` returns code {test_link}')
Expand Down Expand Up @@ -530,14 +530,14 @@ async def review_feeds_status(feed_type: str = None):
failed_channels.append([FEED_NAME, CHANNEL])
if len(failed_feeds) > 0:
# TODO i18n
feed_error_msg = f'Følgende feeds hadde feil ved henting av '\
feed_error_msg = 'Følgende feeds hadde feil ved henting av '\
'linker:\n- {}'.format(
'\n- '.join(failed_feeds)
)
await discord_commands.log_to_bot_channel(feed_error_msg)
if len(failed_channels) > 0:
# TODO i18n
channel_error_msg = f'Følgende feeds hadde feil ved posting til '\
channel_error_msg = 'Følgende feeds hadde feil ved posting til '\
'valgte kanaler:\n- {}'.format(
'\n- '.join(f'{failed_channels[0]}: {failed_channels[1]}')
)
Expand All @@ -562,9 +562,9 @@ def link_similar_to_logged_post(link: str, feed_log: list):
'''
for log_item in feed_log:
if file_io.check_similarity(log_item[0], link):
log.debug(f'Found similar link log)')
log.debug('Found similar link log)')
return True
log.debug(f'No similar link found')
log.debug('No similar link found')
return False


Expand Down Expand Up @@ -664,7 +664,7 @@ async def process_links_for_posting_or_editing(
embed.set_image(url=item['img'])
embed.set_footer(text=item['pod_description'])
log.debug(
f'Sending this embed to channel: ', pretty=embed
'Sending this embed to channel: ', pretty=embed
)
await discord_commands.post_to_channel(
CHANNEL, embed_in=embed
Expand Down
12 changes: 8 additions & 4 deletions sausage_bot/util/net_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async def check_spotify_podcast(url):
pod_id = re.search(r'.*/show/([a-zA-Z0-9]+).*', url).group(1)
try:
_show = _spotipy.show(pod_id)
log.debug(f'`_show`: ', pretty=_show)
log.debug('`_show`: ', pretty=_show)
return _show
except Exception as e:
log.error(f'ERROR: {e}')
Expand Down Expand Up @@ -120,7 +120,7 @@ async def get_spotify_podcast_links(feed):
temp_info['img'] = ep['images'][0]['url']
temp_info['id'] = ep['id']
temp_info['duration'] = ep['duration_ms'] * 1000
log.verbose(f'Populated `temp_info`: ', pretty=temp_info)
log.verbose('Populated `temp_info`: ', pretty=temp_info)
items_out['items'].append(temp_info)
log.debug(
'len of `items_out[\'items\']` is {}'.format(
Expand Down Expand Up @@ -252,7 +252,9 @@ async def make_event_start_stop(date, time=None):
try:
start_date = await datetime_handling.get_dt('date', dt=start_dt)
log.debug(f'Making `start_date` {start_date}')
start_time = await datetime_handling.get_dt('time', sep=':', dt=start_dt)
start_time = await datetime_handling.get_dt(
'time', sep=':', dt=start_dt
)
log.debug(f'Making `start_time` {start_time}')
# Make a startdate for the event that starts 30 minutes before
# the match
Expand All @@ -262,7 +264,9 @@ async def make_event_start_stop(date, time=None):
log.debug(f'`start_event` is {start_event}')
# Make an enddate for the event that should stop approximately
# 30 minutes after the match is over
end_dt = await datetime_handling.change_dt(start_dt, 'add', 2.5, 'hours')
end_dt = await datetime_handling.change_dt(
start_dt, 'add', 2.5, 'hours'
)
log.debug(f'`end_dt` is {end_dt}')
# Make the epochs that the event will use
event_start_epoch = await datetime_handling.get_dt(dt=start_event)
Expand Down

0 comments on commit fab54b0

Please sign in to comment.