diff --git a/robocop_ng/__init__.py b/robocop_ng/__init__.py index 311dee7..799ed71 100755 --- a/robocop_ng/__init__.py +++ b/robocop_ng/__init__.py @@ -1,14 +1,14 @@ +import asyncio +import logging.handlers import os import sys -import logging -import logging.handlers -import asyncio -import aiohttp -import config +import aiohttp import discord from discord.ext import commands +from robocop_ng import config + # TODO: check __name__ for __main__ nerd script_name = os.path.basename(__file__).split(".")[0] @@ -61,6 +61,7 @@ bot.config = config bot.script_name = script_name bot.wanted_jsons = wanted_jsons + async def get_channel_safe(self, id): res = self.get_channel(id) if res is None: @@ -68,8 +69,10 @@ async def get_channel_safe(self, id): return res + commands.Bot.get_channel_safe = get_channel_safe + @bot.event async def on_ready(): aioh = {"User-Agent": f"{script_name}/1.0'"} @@ -165,7 +168,7 @@ async def on_command_error(ctx, error): "to run this command in the current channel." ) elif isinstance(error, commands.CommandInvokeError) and ( - "Cannot send messages to this user" in error_text + "Cannot send messages to this user" in error_text ): return await ctx.send( f"{ctx.author.mention}: I can't DM you.\n" @@ -186,14 +189,15 @@ async def on_command_error(ctx, error): # Keep a list of commands that involve mentioning users # and can involve users leaving/getting banned + # noinspection NonAsciiCharacters,PyPep8Naming ಠ_ಠ = ["warn", "kick", "ban"] if isinstance(error, commands.BadArgument): # and if said commands get used, add a specific notice. if ctx.command.name in ಠ_ಠ: help_text = ( - "This probably means that user left (or already got kicked/banned).\n" - + help_text + "This probably means that user left (or already got kicked/banned).\n" + + help_text ) return await ctx.send( @@ -217,7 +221,7 @@ async def on_message(message): # an allowed command welcome_allowed = ["reset", "kick", "ban", "warn"] if message.channel.id == config.welcome_channel and not any( - cmd in message.content for cmd in welcome_allowed + cmd in message.content for cmd in welcome_allowed ): return diff --git a/robocop_ng/cogs/admin.py b/robocop_ng/cogs/admin.py index 64e6475..aec53a2 100644 --- a/robocop_ng/cogs/admin.py +++ b/robocop_ng/cogs/admin.py @@ -1,11 +1,13 @@ +import inspect +import re +import traceback + import discord from discord.ext import commands from discord.ext.commands import Cog -import traceback -import inspect -import re -import config -from helpers.checks import check_if_bot_manager + +from robocop_ng import config +from robocop_ng.helpers.checks import check_if_bot_manager class Admin(Cog): diff --git a/robocop_ng/cogs/basic.py b/robocop_ng/cogs/basic.py index 78b2da9..c439651 100644 --- a/robocop_ng/cogs/basic.py +++ b/robocop_ng/cogs/basic.py @@ -1,9 +1,11 @@ import time -import config + import discord from discord.ext import commands from discord.ext.commands import Cog +from robocop_ng import config + class Basic(Cog): def __init__(self, bot): @@ -40,7 +42,7 @@ class Basic(Cog): title="Robocop-NG", url=config.source_url, description=config.embed_desc ) - embed.set_thumbnail(url=self.bot.user.avatar_url) + embed.set_thumbnail(url=str(self.bot.user.display_avatar)) await ctx.send(embed=embed) diff --git a/robocop_ng/cogs/basic_reswitched.py b/robocop_ng/cogs/basic_reswitched.py index be3b3de..f2576b7 100644 --- a/robocop_ng/cogs/basic_reswitched.py +++ b/robocop_ng/cogs/basic_reswitched.py @@ -1,7 +1,8 @@ -import config from discord.ext import commands from discord.ext.commands import Cog +from robocop_ng import config + class BasicReswitched(Cog): def __init__(self, bot): diff --git a/robocop_ng/cogs/err.py b/robocop_ng/cogs/err.py index 09f3774..660d565 100644 --- a/robocop_ng/cogs/err.py +++ b/robocop_ng/cogs/err.py @@ -1,9 +1,10 @@ import re -import discord +import discord from discord.ext import commands from discord.ext.commands import Cog -from helpers.errcodes import * + +from robocop_ng.helpers.errcodes import * class Err(Cog): @@ -142,7 +143,7 @@ class Err(Cog): embed.add_field(name="Description", value=desc, inline=True) if "ban" in err_description: - embed.set_footer("F to you | Console: Switch") + embed.set_footer(text="F to you | Console: Switch") else: embed.set_footer(text="Console: Switch") diff --git a/robocop_ng/cogs/imagemanip.py b/robocop_ng/cogs/imagemanip.py index 1b15082..bfa54f2 100644 --- a/robocop_ng/cogs/imagemanip.py +++ b/robocop_ng/cogs/imagemanip.py @@ -1,13 +1,15 @@ +import textwrap + +import PIL.Image +import PIL.ImageDraw +import PIL.ImageFilter +import PIL.ImageFont +import PIL.ImageOps import discord from discord.ext import commands from discord.ext.commands import Cog -from helpers.checks import check_if_staff_or_ot -import textwrap -import PIL.Image -import PIL.ImageFilter -import PIL.ImageOps -import PIL.ImageFont -import PIL.ImageDraw + +from robocop_ng.helpers.checks import check_if_staff_or_ot class ImageManip(Cog): diff --git a/robocop_ng/cogs/invites.py b/robocop_ng/cogs/invites.py index 881ef6a..d981fa7 100644 --- a/robocop_ng/cogs/invites.py +++ b/robocop_ng/cogs/invites.py @@ -1,8 +1,11 @@ +import json + +import discord from discord.ext import commands from discord.ext.commands import Cog -from helpers.checks import check_if_collaborator -import config -import json + +from robocop_ng import config +from robocop_ng.helpers.checks import check_if_collaborator class Invites(Cog): diff --git a/robocop_ng/cogs/links.py b/robocop_ng/cogs/links.py index 7341fc3..6d0d725 100644 --- a/robocop_ng/cogs/links.py +++ b/robocop_ng/cogs/links.py @@ -1,8 +1,9 @@ import discord -import config from discord.ext import commands from discord.ext.commands import Cog +from robocop_ng import config + class Links(Cog): """ diff --git a/robocop_ng/cogs/lists.py b/robocop_ng/cogs/lists.py index bb3867a..f4c6abb 100644 --- a/robocop_ng/cogs/lists.py +++ b/robocop_ng/cogs/lists.py @@ -1,11 +1,12 @@ -import config -import discord import io -import urllib.parse import os.path + +import discord from discord.ext import commands from discord.ext.commands import Cog +from robocop_ng import config + class Lists(Cog): """ diff --git a/robocop_ng/cogs/lockdown.py b/robocop_ng/cogs/lockdown.py index c9c6796..b3ae8e2 100644 --- a/robocop_ng/cogs/lockdown.py +++ b/robocop_ng/cogs/lockdown.py @@ -1,8 +1,9 @@ +import discord from discord.ext import commands from discord.ext.commands import Cog -import config -import discord -from helpers.checks import check_if_staff + +from robocop_ng import config +from robocop_ng.helpers.checks import check_if_staff class Lockdown(Cog): diff --git a/robocop_ng/cogs/logfilereader.py b/robocop_ng/cogs/logfilereader.py index 1996c5c..fb383b4 100644 --- a/robocop_ng/cogs/logfilereader.py +++ b/robocop_ng/cogs/logfilereader.py @@ -5,7 +5,7 @@ import aiohttp from discord import Colour, Embed from discord.ext.commands import Cog -import config +from robocop_ng import config logging.basicConfig( format="%(asctime)s (%(levelname)s) %(message)s (Line %(lineno)d)", @@ -735,7 +735,7 @@ class LogFileReader(Cog): await reply_message.edit( content=f"Error: Couldn't parse log; parser threw `{type(error).__name__}` exception." ) - print(logging.warn(error)) + print(logging.warning(error)) else: duplicate_log_file = next( ( diff --git a/robocop_ng/cogs/logs.py b/robocop_ng/cogs/logs.py index efeb024..560d4d0 100644 --- a/robocop_ng/cogs/logs.py +++ b/robocop_ng/cogs/logs.py @@ -1,10 +1,12 @@ -import discord -from discord.ext.commands import Cog import json import re -import config -from helpers.restrictions import get_user_restrictions -from helpers.checks import check_if_staff + +import discord +from discord.ext.commands import Cog + +from robocop_ng import config +from robocop_ng.helpers.checks import check_if_staff +from robocop_ng.helpers.restrictions import get_user_restrictions class Logs(Cog): @@ -138,7 +140,7 @@ class Logs(Cog): embed = discord.Embed( color=discord.Color.dark_red(), title=f"Warns for {escaped_name}" ) - embed.set_thumbnail(url=member.avatar_url) + embed.set_thumbnail(url=str(member.display_avatar)) for idx, warn in enumerate(warns[str(member.id)]["warns"]): embed.add_field( name=f"{idx + 1}: {warn['timestamp']}", @@ -188,7 +190,7 @@ class Logs(Cog): # Show a message embed embed = discord.Embed(description=regd) embed.set_author( - name=message.author.display_name, icon_url=message.author.avatar_url + name=message.author.display_name, icon_url=str(message.author.display_avatar) ) await spy_channel.send(msg, embed=embed) diff --git a/robocop_ng/cogs/meme.py b/robocop_ng/cogs/meme.py index a26f327..f7d8453 100644 --- a/robocop_ng/cogs/meme.py +++ b/robocop_ng/cogs/meme.py @@ -1,11 +1,13 @@ +import datetime +import math +import platform import random + import discord from discord.ext import commands from discord.ext.commands import Cog -import math -import platform -from helpers.checks import check_if_staff_or_ot -import datetime + +from robocop_ng.helpers.checks import check_if_staff_or_ot class Meme(Cog): diff --git a/robocop_ng/cogs/mod.py b/robocop_ng/cogs/mod.py index a4eedc9..c80c346 100644 --- a/robocop_ng/cogs/mod.py +++ b/robocop_ng/cogs/mod.py @@ -1,11 +1,13 @@ +import io + import discord from discord.ext import commands from discord.ext.commands import Cog -import config -from helpers.checks import check_if_staff, check_if_bot_manager -from helpers.userlogs import userlog -from helpers.restrictions import add_restriction, remove_restriction -import io + +from robocop_ng import config +from robocop_ng.helpers.checks import check_if_staff, check_if_bot_manager +from robocop_ng.helpers.restrictions import add_restriction, remove_restriction +from robocop_ng.helpers.userlogs import userlog class Mod(Cog): @@ -712,28 +714,28 @@ class Mod(Cog): fetchedMessages = fetchedMessages[:-1] # Loop over the messages fetched - for messages in fetchedMessages: - # if the message is embeded already - if messages.embeds: + for message in fetchedMessages: + # if the message is embedded already + if message.embeds: # set the embed message to the old embed object - embedMessage = messages.embeds[0] + embedMessage = message.embeds[0] # else else: # Create embed message object and set content to original - embedMessage = discord.Embed(description=messages.content) + embedMessage = discord.Embed(description=message.content) avatar_url = None - if messages.author.avatar is not None: - avatar_url = messages.author.avatar.url + if message.author.display_avatar is not None: + avatar_url = str(message.author.display_avatar) # set the embed message author to original author embedMessage.set_author( - name=messages.author, icon_url=avatar_url + name=message.author, icon_url=avatar_url ) # if message has attachments add them - if messages.attachments: - for i in messages.attachments: + if message.attachments: + for i in message.attachments: embedMessage.set_image(url=i.proxy_url) # Send to the desired channel diff --git a/robocop_ng/cogs/mod_note.py b/robocop_ng/cogs/mod_note.py index e2aac25..27f6916 100644 --- a/robocop_ng/cogs/mod_note.py +++ b/robocop_ng/cogs/mod_note.py @@ -1,8 +1,9 @@ import discord from discord.ext import commands from discord.ext.commands import Cog -from helpers.checks import check_if_staff -from helpers.userlogs import userlog + +from robocop_ng.helpers.checks import check_if_staff +from robocop_ng.helpers.userlogs import userlog class ModNote(Cog): diff --git a/robocop_ng/cogs/mod_reacts.py b/robocop_ng/cogs/mod_reacts.py index f48a413..35680c3 100644 --- a/robocop_ng/cogs/mod_reacts.py +++ b/robocop_ng/cogs/mod_reacts.py @@ -1,9 +1,11 @@ import asyncio + import discord from discord.ext import commands from discord.ext.commands import Cog -import config -from helpers.checks import check_if_staff + +from robocop_ng import config +from robocop_ng.helpers.checks import check_if_staff class ModReact(Cog): diff --git a/robocop_ng/cogs/mod_reswitched.py b/robocop_ng/cogs/mod_reswitched.py index 4966ec4..167ffe6 100644 --- a/robocop_ng/cogs/mod_reswitched.py +++ b/robocop_ng/cogs/mod_reswitched.py @@ -1,7 +1,8 @@ -import config from discord.ext import commands from discord.ext.commands import Cog -from helpers.checks import check_if_staff + +from robocop_ng import config +from robocop_ng.helpers.checks import check_if_staff class ModReswitched(Cog): diff --git a/robocop_ng/cogs/mod_timed.py b/robocop_ng/cogs/mod_timed.py index 812b053..745e0d8 100644 --- a/robocop_ng/cogs/mod_timed.py +++ b/robocop_ng/cogs/mod_timed.py @@ -1,12 +1,14 @@ -import discord -import config from datetime import datetime + +import discord from discord.ext import commands from discord.ext.commands import Cog -from helpers.checks import check_if_staff -from helpers.robocronp import add_job -from helpers.userlogs import userlog -from helpers.restrictions import add_restriction + +from robocop_ng import config +from robocop_ng.helpers.checks import check_if_staff +from robocop_ng.helpers.restrictions import add_restriction +from robocop_ng.helpers.robocronp import add_job +from robocop_ng.helpers.userlogs import userlog class ModTimed(Cog): diff --git a/robocop_ng/cogs/mod_userlog.py b/robocop_ng/cogs/mod_userlog.py index 9a8ea61..4dcb9a8 100644 --- a/robocop_ng/cogs/mod_userlog.py +++ b/robocop_ng/cogs/mod_userlog.py @@ -1,10 +1,12 @@ +import json + import discord from discord.ext import commands from discord.ext.commands import Cog -import config -import json -from helpers.checks import check_if_staff -from helpers.userlogs import get_userlog, set_userlog, userlog_event_types + +from robocop_ng import config +from robocop_ng.helpers.checks import check_if_staff +from robocop_ng.helpers.userlogs import get_userlog, set_userlog, userlog_event_types class ModUserlog(Cog): @@ -233,7 +235,7 @@ class ModUserlog(Cog): await ctx.send( f"user = {user_name}\n" f"id = {user.id}\n" - f"avatar = {user.avatar_url}\n" + f"avatar = {user.display_avatar}\n" f"bot = {user.bot}\n" f"created_at = {user.created_at}\n" f"display_name = {display_name}\n" diff --git a/robocop_ng/cogs/mod_watch.py b/robocop_ng/cogs/mod_watch.py index d04d656..b4741e1 100644 --- a/robocop_ng/cogs/mod_watch.py +++ b/robocop_ng/cogs/mod_watch.py @@ -1,8 +1,9 @@ import discord from discord.ext import commands from discord.ext.commands import Cog -from helpers.checks import check_if_staff -from helpers.userlogs import setwatch + +from robocop_ng.helpers.checks import check_if_staff +from robocop_ng.helpers.userlogs import setwatch class ModWatch(Cog): diff --git a/robocop_ng/cogs/pin.py b/robocop_ng/cogs/pin.py index 6a964b1..60d87e2 100644 --- a/robocop_ng/cogs/pin.py +++ b/robocop_ng/cogs/pin.py @@ -1,12 +1,13 @@ -import config -from discord.ext import commands -from discord.ext.commands import Cog -from discord.enums import MessageType -from discord import Embed import aiohttp import gidgethub.aiohttp -from helpers.checks import check_if_collaborator -from helpers.checks import check_if_pin_channel +from discord import Embed +from discord.enums import MessageType +from discord.ext import commands +from discord.ext.commands import Cog + +from robocop_ng import config +from robocop_ng.helpers.checks import check_if_collaborator +from robocop_ng.helpers.checks import check_if_pin_channel class Pin(Cog): diff --git a/robocop_ng/cogs/remind.py b/robocop_ng/cogs/remind.py index c402b3e..7381ab0 100644 --- a/robocop_ng/cogs/remind.py +++ b/robocop_ng/cogs/remind.py @@ -1,10 +1,12 @@ -import discord import asyncio import time from datetime import datetime + +import discord from discord.ext import commands from discord.ext.commands import Cog -from helpers.robocronp import add_job, get_crontab + +from robocop_ng.helpers.robocronp import add_job, get_crontab class Remind(Cog): diff --git a/robocop_ng/cogs/robocronp.py b/robocop_ng/cogs/robocronp.py index e1188c8..b5076c1 100644 --- a/robocop_ng/cogs/robocronp.py +++ b/robocop_ng/cogs/robocronp.py @@ -1,12 +1,14 @@ -import config import time -import discord import traceback + +import discord from discord.ext import commands, tasks from discord.ext.commands import Cog -from helpers.robocronp import get_crontab, delete_job -from helpers.restrictions import remove_restriction -from helpers.checks import check_if_staff + +from robocop_ng import config +from robocop_ng.helpers.checks import check_if_staff +from robocop_ng.helpers.restrictions import remove_restriction +from robocop_ng.helpers.robocronp import get_crontab, delete_job class Robocronp(Cog): diff --git a/robocop_ng/cogs/ryujinx_reactionroles.py b/robocop_ng/cogs/ryujinx_reactionroles.py index 480a624..1de12c2 100644 --- a/robocop_ng/cogs/ryujinx_reactionroles.py +++ b/robocop_ng/cogs/ryujinx_reactionroles.py @@ -1,12 +1,13 @@ import collections import json -import config import os import discord from discord.ext import commands from discord.ext.commands import Cog -from helpers.checks import check_if_staff + +from robocop_ng import config +from robocop_ng.helpers.checks import check_if_staff class RyujinxReactionRoles(Cog): diff --git a/robocop_ng/cogs/ryujinx_verification.py b/robocop_ng/cogs/ryujinx_verification.py index dbfd751..4ee3d51 100644 --- a/robocop_ng/cogs/ryujinx_verification.py +++ b/robocop_ng/cogs/ryujinx_verification.py @@ -1,9 +1,9 @@ import discord from discord.ext import commands from discord.ext.commands import Cog -import config -import random -from helpers.checks import check_if_staff + +from robocop_ng import config +from robocop_ng.helpers.checks import check_if_staff class RyujinxVerification(Cog): diff --git a/robocop_ng/cogs/sar.py b/robocop_ng/cogs/sar.py index 21f83cd..094ea83 100644 --- a/robocop_ng/cogs/sar.py +++ b/robocop_ng/cogs/sar.py @@ -1,7 +1,8 @@ -import config from discord.ext import commands from discord.ext.commands import Cog -from helpers.checks import check_if_staff_or_ot + +from robocop_ng import config +from robocop_ng.helpers.checks import check_if_staff_or_ot class SAR(Cog): diff --git a/robocop_ng/cogs/verification.py b/robocop_ng/cogs/verification.py index 9756c9f..6d658a2 100644 --- a/robocop_ng/cogs/verification.py +++ b/robocop_ng/cogs/verification.py @@ -1,13 +1,15 @@ +import asyncio +import hashlib +import itertools +import random +from inspect import cleandoc + import discord from discord.ext import commands from discord.ext.commands import Cog -import asyncio -import config -import random -from inspect import cleandoc -import hashlib -import itertools -from helpers.checks import check_if_staff + +from robocop_ng import config +from robocop_ng.helpers.checks import check_if_staff class Verification(Cog): diff --git a/robocop_ng/cogs/yubicootp.py b/robocop_ng/cogs/yubicootp.py index 6599987..d7c888d 100644 --- a/robocop_ng/cogs/yubicootp.py +++ b/robocop_ng/cogs/yubicootp.py @@ -1,10 +1,12 @@ -from discord.ext.commands import Cog -import re -import config -import secrets import asyncio import base64 import hmac +import re +import secrets + +from discord.ext.commands import Cog + +from robocop_ng import config class YubicoOTP(Cog): diff --git a/robocop_ng/helpers/checks.py b/robocop_ng/helpers/checks.py index 70a5c70..bbb2809 100644 --- a/robocop_ng/helpers/checks.py +++ b/robocop_ng/helpers/checks.py @@ -1,4 +1,4 @@ -import config +from robocop_ng import config def check_if_staff(ctx):