Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #25

Closed
wants to merge 19 commits into from
Prev Previous commit
Next Next commit
General fixes for pham's refactor
  • Loading branch information
MujyKun committed Dec 29, 2020
commit 97132732994a5b2ecea90c2f3fbbcb6ab1750a35
2 changes: 1 addition & 1 deletion module/Archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Archive(commands.Cog):
@staticmethod
async def on_message(message, is_owner=False):
if message.author.bot:
return None
return
if is_owner:
try:
def check(m):
Expand Down
4 changes: 2 additions & 2 deletions module/BotMod.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ async def mod_on_message(message):
message_channel = message.channel
message_content = message.content
if message_sender.id == keys.bot_id:
return None
return
if 'closedm' in message_content or 'createdm' in message_content:
return None
return
for user_id in ex.cache.mod_mail:
channel_id = ex.cache.mod_mail.get(user_id)
mod_channel = await ex.client.fetch_channel(channel_id)
Expand Down
6 changes: 3 additions & 3 deletions module/CustomCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class CustomCommands(commands.Cog):
@staticmethod
async def process_custom_commands(message):
# custom server commands
if not message.content and message.author.bot:
return None
if not message.content or message.author.bot:
return

if await ex.u_miscellaneous.check_if_bot_banned(message.author.id):
return None
return

guild_id = await ex.get_server_id(message)
current_message_prefix = message.content[0:len(keys.bot_prefix)]
Expand Down
15 changes: 7 additions & 8 deletions module/GroupMembers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,15 @@ async def check_user_limit(message_sender, message_channel, no_vote_limit=False)
# amount of votes that can be sent without voting.
limit = keys.idol_no_vote_send_limit
if message_sender.id not in ex.cache.commands_used:
return None
return
if not await ex.u_patreon.check_if_patreon(message_sender.id) and ex.cache.commands_used[message_sender.id][0] > limit:
# noinspection PyPep8
if not await ex.u_patreon.check_if_patreon(message_channel.guild.owner.id, super=True) and not no_vote_limit:
if not await ex.u_patreon.check_if_patreon(message_channel.guild.owner.id, super_patron=True) and not no_vote_limit:
return await message_channel.send(patron_message)
elif ex.cache.commands_used[message_sender.id][0] > owner_super_patron_benefit and not no_vote_limit:
return await message_channel.send(patron_message)
else:
return True
return False


# noinspection PyPep8
Expand Down Expand Up @@ -105,8 +104,8 @@ class GroupMembers(commands.Cog):
async def on_message2(message):
# create modifiable var without altering original
channel = message.channel
if message.author.bot or not ex.u_group_members.check_channel_sending_photos(channel.id) or ex.u_miscellaneous.check_if_temp_channel(channel.id):
return None
if message.author.bot or not await ex.u_group_members.check_channel_sending_photos(channel.id) or await ex.u_miscellaneous.check_if_temp_channel(channel.id):
return
try:
if await ex.u_group_members.check_server_sending_photos(message.guild.id):
channel = await ex.u_group_members.get_channel_sending_photos(message.guild.id)
Expand All @@ -129,8 +128,8 @@ async def on_message2(message):
# we just need to make sure it has the bot's default prefix
# however this means if a user changes the prefix and uses the bot's default prefix
# it will still process idol photos, but not regular commands.
if message.content[0:len(keys.bot_prefix)] != keys.bot_prefix and message.content.lower() == f"{keys.bot_prefix}null":
return None
if message.content[0:len(keys.bot_prefix)] != keys.bot_prefix or message.content.lower() == f"{keys.bot_prefix}null":
return
message_content = message.content[len(keys.bot_prefix):len(message.content)]
server_id = await ex.get_server_id(message)
members = await ex.u_group_members.get_idol_where_member_matches_name(message_content, server_id=server_id)
Expand Down Expand Up @@ -306,7 +305,7 @@ async def groups(self, ctx):
embed_list = []
counter = 1
for group in ex.cache.groups:
if group.name == "NULL" or is_mod:
if group.name == "NULL" and not is_mod:
continue
if is_mod:
embed.insert_field_at(counter, name=f"{group.name} ({group.id})", value=f"{group.photo_count} Photos", inline=True)
Expand Down
2 changes: 1 addition & 1 deletion module/LastFM.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def get_recent_tracks(response, limit):
async def create_fm_embed(title, stats_info, inline=False, individual=False):
"""Create and return an embed that matches the format for FM tracks and artists."""
embed = await ex.create_embed(title=title, color=ex.get_random_color())
for name, value in stats_info:
for name, value, image_url in stats_info:
if not individual:
embed.add_field(name=name, value=value, inline=inline)
else:
Expand Down
25 changes: 9 additions & 16 deletions module/Miscellaneous.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ async def on_message_notifications(message):
# user phrase notifications
try:
if message.author.bot:
return None
return
for guild_id, user_id, phrase in ex.cache.user_notifications:
message_split = message.content.lower().split(" ")
if phrase not in message_split or guild_id != message.guild.id:
return None
return
if message.author.id == user_id or user_id not in [member.id for member in message.channel.members]:
return None
return
log.console(f"message_notifications 1 - {phrase} to {user_id}")
dm_channel = await ex.get_dm_channel(user_id)
log.console(f"message_notifications 2 - {phrase} to {user_id}")
Expand All @@ -29,7 +29,7 @@ async def on_message_notifications(message):
new_message_content = f"{message.content[0:start_loc]}`{message.content[start_loc:end_loc]}`{message.content[end_loc:len(message.content)]}"
title_desc = f"""
Phrase: {phrase}
Message Author: {message_sender}
Message Author: {message.author}

**Message:** {new_message_content}
[Click to go to the Message]({message.jump_url})
Expand Down Expand Up @@ -297,7 +297,6 @@ async def clearnword(self, ctx, user: discord.Member = None):
ex.cache.n_word_counter[user.id] = None
await ctx.send("**> Cleared.**")


@commands.command(aliases=["nwl"])
async def nwordleaderboard(self, ctx):
"""Shows leaderboards for how many times the nword has been said. [Format: %nwl]"""
Expand All @@ -316,7 +315,7 @@ async def nwordleaderboard(self, ctx):
except:
# if the user is not in discord.py's member cache, then set the user's name to null.
user_name = "NULL"
embed.add_field(name=f"{count_loop+1}) {user_name} ({user_id})", value=value)
embed.add_field(name=f"{count+1}) {user_name} ({user_id})", value=value)
await ctx.send(embed=embed)

@commands.command(aliases=['rand', 'randint', 'r'])
Expand All @@ -336,7 +335,7 @@ async def flip(self, ctx):
async def urban(self, ctx, term=None, number=1, override=0):
"""Search a term through UrbanDictionary. Underscores are spaces.
[Format: %urban (term) (definition number)][Aliases: define,u]"""
if not ctx.channel.is_nsfw() and override != 0:
if not ctx.channel.is_nsfw() and not override == 1:
server_prefix = await ex.get_server_prefix_by_context(ctx)
return await ctx.send(f">>> **This text channel must be NSFW to use {server_prefix}"
f"urban (Guidelines set by top.gg).**\nTo override this, You may add a **1** after the "
Expand All @@ -349,7 +348,7 @@ async def urban(self, ctx, term=None, number=1, override=0):
async with ex.session.get(url, headers=keys.X_RapidAPI_headers, params=querystring) as r:
ex.cache.urban_per_minute += 1
if r.status != 200:
log.console(r.status)
log.console(f"The connection to the UrbanDictionary API failed. -> {r.status}")
return await ctx.send("> **The connection to the UrbanDictionary API failed.**")
result = await r.json()
try:
Expand All @@ -358,7 +357,6 @@ async def urban(self, ctx, term=None, number=1, override=0):
return await ctx.send(f"> **It is not possible to find definition number `{number}` for the word: `{term}`.**")
await ctx.send(f">>> **`Word: {term}`\n`Definition Number: {number}`\n{first_result['definition']}**")


@commands.command()
async def invite(self, ctx):
"""Invite Link to add Irene to a server."""
Expand Down Expand Up @@ -444,14 +442,9 @@ async def servers(self, ctx):
icon_url='https://cdn.discordapp.com/emojis/693392862611767336.gif?v=1')
embed.set_footer(text="Thanks for using Irene.",
icon_url='https://cdn.discordapp.com/emojis/683932986818822174.gif?v=1')
guilds_ordered = []
for guild in guilds:
guild_info = [guild.id, guild.member_count]
guilds_ordered.append(guild_info)
guilds_ordered = [[guild.id, guild.member_count] for guild in guilds]
guilds_ordered.sort(key=lambda server_info: server_info[1])
guild_ids_sorted = []
for guild in guilds_ordered:
guild_ids_sorted.append(guild[0])
guild_ids_sorted = [guild[0] for guild in guilds_ordered]
embed_list = []
try:
for main_guild_id in guild_ids_sorted:
Expand Down
1 change: 0 additions & 1 deletion module/Moderator.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ async def disableinteraction(self, ctx, interaction=None):
await ex.u_miscellaneous.disable_interaction(ctx.guild.id, interaction)
await ctx.send(f"> **{interaction} has been disabled in this server.**")


@staticmethod
async def get_mute_role(ctx):
mute_roles = await ex.conn.fetch("SELECT roleid FROM general.muteroles")
Expand Down
43 changes: 22 additions & 21 deletions module/Music.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,22 @@ class Music(commands.Cog):
@tasks.loop(seconds=30, minutes=1, hours=0, reconnect=True)
async def check_voice_clients(self):
if not ex.client.loop.is_running():
return None
return
try:
for voice_client in ex.client.voice_clients:
if voice_client.is_connected() and voice_client.channel.members and voice_client.is_playing():
try:
songs_queued = queued[voice_client.guild.id]
if songs_queued:
channel = songs_queued[0][1]
msg = f"> **There are no users in this voice channel. Resetting queue and leaving.**"
await channel.send(msg)
except:
pass
self.reset_queue_for_guild(voice_client.guild.id)
voice_client.stop()
await voice_client.disconnect()
if voice_client.is_connected() and voice_client.channel.members:
if voice_client.is_playing():
try:
songs_queued = queued[voice_client.guild.id]
if songs_queued:
channel = songs_queued[0][1]
msg = f"> **There are no users in this voice channel. Resetting queue and leaving.**"
await channel.send(msg)
except:
pass
self.reset_queue_for_guild(voice_client.guild.id)
voice_client.stop()
await voice_client.disconnect()
keep_files = []
for key in queued:
file_name = (queued[key][0][2])
Expand All @@ -125,7 +126,7 @@ def check_user_in_vc(ctx):
def reset_queue_for_guild(guild_id):
try:
if not queued[guild_id]:
return None
return
for song in queued[guild_id]:
player = song[0]
file_name = song[2]
Expand All @@ -135,7 +136,7 @@ def reset_queue_for_guild(guild_id):
os.remove(file_name)
except:
pass
queued.pop(guild_id, None)
queued.pop(guild_id, None)
except:
pass

Expand Down Expand Up @@ -293,7 +294,7 @@ async def move(self, ctx, song_number: int):
"""Makes a song the next song to play without skipping the current song. [Format: %move (song number)] """
try:
if not self.check_user_in_vc(ctx):
await ctx.send(f"> **{ctx.author}, we are not in the same voice channel.**")
return await ctx.send(f"> **{ctx.author}, we are not in the same voice channel.**")
song_number = song_number - 1 # account for starting from 0
if not song_number:
return await ctx.send(f"> **You can not move the song currently playing.**")
Expand Down Expand Up @@ -360,7 +361,7 @@ def remove_song_in_queue(self, client_guild_id):
@commands.command(aliases=['p'])
async def play(self, ctx, *, url=None):
"""Plays audio to a voice channel. [Format: %play (title/url)]"""
if url is None:
if not url:
if not ctx.voice_client.is_paused:
return await ctx.send("> The player is not paused. Please enter a title or link to play audio.")
ctx.voice_client.resume()
Expand Down Expand Up @@ -405,7 +406,7 @@ async def play(self, ctx, *, url=None):

def start_next_song(self, error):
if error:
return None
return
all_voice_clients = ex.client.voice_clients
for voice_client in all_voice_clients:
if voice_client.is_playing() or voice_client.is_paused():
Expand Down Expand Up @@ -447,13 +448,13 @@ async def volume(self, ctx, volume: int = 10):
try:
if not self.check_user_in_vc(ctx):
return await ctx.send(f"> **{ctx.author}, we are not in the same voice channel.**")
if volume < 1 or volume > 100:
if 1 > volume > 100:
return await ctx.send(f"> **{ctx.author}, please choose a volume from 1 to 100.**")
else:
if not ctx.voice_client:
return await ctx.send(f"> **{ctx.author}, you are not connected to a voice channel.**")
ctx.voice_client.source.volume = volume / 100
await ctx.send("> **Changed volume to {}%**".format(volume))
await ctx.send(f"> **Changed volume to {volume}%**")
except AttributeError:
await ctx.send(f"> **{ctx.author}, I am not in a voice channel.**")
except Exception as e:
Expand Down Expand Up @@ -495,7 +496,7 @@ async def ensure_voice(ctx):
@queue.before_invoke
@shuffle.before_invoke
async def check_patreon(self, ctx):
if await ex.u_patreon.check_if_patreon(ctx.author.id, super=True) or await ex.u_patreon.check_if_patreon(ctx.guild.owner.id, super=True):
if await ex.u_patreon.check_if_patreon(ctx.author.id, super_patron=True) or await ex.u_patreon.check_if_patreon(ctx.guild.owner.id, super_patron=True):
await self.ensure_voice(ctx)
else:
await ctx.send(f"""**Music is only available to $5 Patreons that support <@{keys.bot_id}>.
Expand Down
8 changes: 4 additions & 4 deletions module/Reminder.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,18 @@ async def reminder_loop(self):
for user_id in ex.cache.reminders:
reminders = ex.cache.reminders.get(user_id)
if not reminders:
return None
return
for remind_id, remind_reason, remind_time in reminders:
try:
current_time = datetime.datetime.now(remind_time.tzinfo)
if current_time < remind_time:
return None
return
dm_channel = await ex.get_dm_channel(user_id=user_id)
if dm_channel:
title_desc = f"This is a reminder to **{remind_reason}**."
embed = await ex.create_embed(title="Reminder", title_desc=title_desc)
await dm_channel.send(embed=embed)
await ex.u_reminder.remove_user_reminder(user_id, remind_id)
except:
# likely forbidden error -> do not have access to dm user
pass
pass # likely forbidden error -> do not have access to dm user

2 changes: 1 addition & 1 deletion module/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Status:
@tasks.loop(seconds=30, minutes=0, hours=0, reconnect=True)
async def change_bot_status_loop(self):
if not ex.client.loop.is_running():
return None
return
try:
random_statuses = [
f'{ex.u_miscellaneous.get_server_count()} servers.',
Expand Down
3 changes: 1 addition & 2 deletions util/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ async def get_channels_logged():
"""Get all the channels that are being logged."""
return ex.cache.list_of_logged_channels

@staticmethod
async def add_to_logging(server_id, channel_id): # return true if status is on
async def add_to_logging(self, server_id, channel_id): # return true if status is on
"""Add a channel to be logged."""
if (ex.first_result(
await ex.conn.fetchrow("SELECT COUNT(*) FROM logging.servers WHERE serverid = $1", server_id))) == 0:
Expand Down
3 changes: 1 addition & 2 deletions util/weverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

# noinspection PyBroadException,PyPep8
class Weverse:
@staticmethod
async def add_weverse_channel(channel_id, community_name):
async def add_weverse_channel(self, channel_id, community_name):
"""Add a channel to get updates for a community"""
community_name = community_name.lower()
await ex.conn.execute("INSERT INTO weverse.channels(channelid, communityname) VALUES($1, $2)", channel_id,
Expand Down