Fix errors when trying to access an avatar and some cleanup (#22)

* Replace avatar_url with str(display_avatar)

* Rewrite imports and resolve a few warnings
This commit is contained in:
TSRBerry 2023-03-09 23:01:10 +01:00 committed by GitHub
parent 950b3f577b
commit bd5f37086e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 161 additions and 117 deletions

View file

@ -1,14 +1,14 @@
import asyncio
import logging.handlers
import os import os
import sys import sys
import logging
import logging.handlers
import asyncio
import aiohttp
import config
import aiohttp
import discord import discord
from discord.ext import commands from discord.ext import commands
from robocop_ng import config
# TODO: check __name__ for __main__ nerd # TODO: check __name__ for __main__ nerd
script_name = os.path.basename(__file__).split(".")[0] script_name = os.path.basename(__file__).split(".")[0]
@ -61,6 +61,7 @@ bot.config = config
bot.script_name = script_name bot.script_name = script_name
bot.wanted_jsons = wanted_jsons bot.wanted_jsons = wanted_jsons
async def get_channel_safe(self, id): async def get_channel_safe(self, id):
res = self.get_channel(id) res = self.get_channel(id)
if res is None: if res is None:
@ -68,8 +69,10 @@ async def get_channel_safe(self, id):
return res return res
commands.Bot.get_channel_safe = get_channel_safe commands.Bot.get_channel_safe = get_channel_safe
@bot.event @bot.event
async def on_ready(): async def on_ready():
aioh = {"User-Agent": f"{script_name}/1.0'"} 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." "to run this command in the current channel."
) )
elif isinstance(error, commands.CommandInvokeError) and ( 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( return await ctx.send(
f"{ctx.author.mention}: I can't DM you.\n" 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 # Keep a list of commands that involve mentioning users
# and can involve users leaving/getting banned # and can involve users leaving/getting banned
# noinspection NonAsciiCharacters,PyPep8Naming
ಠ_ಠ = ["warn", "kick", "ban"] ಠ_ಠ = ["warn", "kick", "ban"]
if isinstance(error, commands.BadArgument): if isinstance(error, commands.BadArgument):
# and if said commands get used, add a specific notice. # and if said commands get used, add a specific notice.
if ctx.command.name in ಠ_ಠ: if ctx.command.name in ಠ_ಠ:
help_text = ( help_text = (
"This probably means that user left (or already got kicked/banned).\n" "This probably means that user left (or already got kicked/banned).\n"
+ help_text + help_text
) )
return await ctx.send( return await ctx.send(
@ -217,7 +221,7 @@ async def on_message(message):
# an allowed command # an allowed command
welcome_allowed = ["reset", "kick", "ban", "warn"] welcome_allowed = ["reset", "kick", "ban", "warn"]
if message.channel.id == config.welcome_channel and not any( 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 return

View file

@ -1,11 +1,13 @@
import inspect
import re
import traceback
import discord import discord
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Cog from discord.ext.commands import Cog
import traceback
import inspect from robocop_ng import config
import re from robocop_ng.helpers.checks import check_if_bot_manager
import config
from helpers.checks import check_if_bot_manager
class Admin(Cog): class Admin(Cog):

View file

@ -1,9 +1,11 @@
import time import time
import config
import discord import discord
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Cog from discord.ext.commands import Cog
from robocop_ng import config
class Basic(Cog): class Basic(Cog):
def __init__(self, bot): def __init__(self, bot):
@ -40,7 +42,7 @@ class Basic(Cog):
title="Robocop-NG", url=config.source_url, description=config.embed_desc 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) await ctx.send(embed=embed)

View file

@ -1,7 +1,8 @@
import config
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Cog from discord.ext.commands import Cog
from robocop_ng import config
class BasicReswitched(Cog): class BasicReswitched(Cog):
def __init__(self, bot): def __init__(self, bot):

View file

@ -1,9 +1,10 @@
import re import re
import discord
import discord
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Cog from discord.ext.commands import Cog
from helpers.errcodes import *
from robocop_ng.helpers.errcodes import *
class Err(Cog): class Err(Cog):
@ -142,7 +143,7 @@ class Err(Cog):
embed.add_field(name="Description", value=desc, inline=True) embed.add_field(name="Description", value=desc, inline=True)
if "ban" in err_description: if "ban" in err_description:
embed.set_footer("F to you | Console: Switch") embed.set_footer(text="F to you | Console: Switch")
else: else:
embed.set_footer(text="Console: Switch") embed.set_footer(text="Console: Switch")

View file

@ -1,13 +1,15 @@
import textwrap
import PIL.Image
import PIL.ImageDraw
import PIL.ImageFilter
import PIL.ImageFont
import PIL.ImageOps
import discord import discord
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Cog from discord.ext.commands import Cog
from helpers.checks import check_if_staff_or_ot
import textwrap from robocop_ng.helpers.checks import check_if_staff_or_ot
import PIL.Image
import PIL.ImageFilter
import PIL.ImageOps
import PIL.ImageFont
import PIL.ImageDraw
class ImageManip(Cog): class ImageManip(Cog):

View file

@ -1,8 +1,11 @@
import json
import discord
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Cog from discord.ext.commands import Cog
from helpers.checks import check_if_collaborator
import config from robocop_ng import config
import json from robocop_ng.helpers.checks import check_if_collaborator
class Invites(Cog): class Invites(Cog):

View file

@ -1,8 +1,9 @@
import discord import discord
import config
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Cog from discord.ext.commands import Cog
from robocop_ng import config
class Links(Cog): class Links(Cog):
""" """

View file

@ -1,11 +1,12 @@
import config
import discord
import io import io
import urllib.parse
import os.path import os.path
import discord
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Cog from discord.ext.commands import Cog
from robocop_ng import config
class Lists(Cog): class Lists(Cog):
""" """

View file

@ -1,8 +1,9 @@
import discord
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Cog from discord.ext.commands import Cog
import config
import discord from robocop_ng import config
from helpers.checks import check_if_staff from robocop_ng.helpers.checks import check_if_staff
class Lockdown(Cog): class Lockdown(Cog):

View file

@ -5,7 +5,7 @@ import aiohttp
from discord import Colour, Embed from discord import Colour, Embed
from discord.ext.commands import Cog from discord.ext.commands import Cog
import config from robocop_ng import config
logging.basicConfig( logging.basicConfig(
format="%(asctime)s (%(levelname)s) %(message)s (Line %(lineno)d)", format="%(asctime)s (%(levelname)s) %(message)s (Line %(lineno)d)",
@ -735,7 +735,7 @@ class LogFileReader(Cog):
await reply_message.edit( await reply_message.edit(
content=f"Error: Couldn't parse log; parser threw `{type(error).__name__}` exception." content=f"Error: Couldn't parse log; parser threw `{type(error).__name__}` exception."
) )
print(logging.warn(error)) print(logging.warning(error))
else: else:
duplicate_log_file = next( duplicate_log_file = next(
( (

View file

@ -1,10 +1,12 @@
import discord
from discord.ext.commands import Cog
import json import json
import re import re
import config
from helpers.restrictions import get_user_restrictions import discord
from helpers.checks import check_if_staff 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): class Logs(Cog):
@ -138,7 +140,7 @@ class Logs(Cog):
embed = discord.Embed( embed = discord.Embed(
color=discord.Color.dark_red(), title=f"Warns for {escaped_name}" 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"]): for idx, warn in enumerate(warns[str(member.id)]["warns"]):
embed.add_field( embed.add_field(
name=f"{idx + 1}: {warn['timestamp']}", name=f"{idx + 1}: {warn['timestamp']}",
@ -188,7 +190,7 @@ class Logs(Cog):
# Show a message embed # Show a message embed
embed = discord.Embed(description=regd) embed = discord.Embed(description=regd)
embed.set_author( 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) await spy_channel.send(msg, embed=embed)

View file

@ -1,11 +1,13 @@
import datetime
import math
import platform
import random import random
import discord import discord
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Cog from discord.ext.commands import Cog
import math
import platform from robocop_ng.helpers.checks import check_if_staff_or_ot
from helpers.checks import check_if_staff_or_ot
import datetime
class Meme(Cog): class Meme(Cog):

View file

@ -1,11 +1,13 @@
import io
import discord import discord
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Cog from discord.ext.commands import Cog
import config
from helpers.checks import check_if_staff, check_if_bot_manager from robocop_ng import config
from helpers.userlogs import userlog from robocop_ng.helpers.checks import check_if_staff, check_if_bot_manager
from helpers.restrictions import add_restriction, remove_restriction from robocop_ng.helpers.restrictions import add_restriction, remove_restriction
import io from robocop_ng.helpers.userlogs import userlog
class Mod(Cog): class Mod(Cog):
@ -712,28 +714,28 @@ class Mod(Cog):
fetchedMessages = fetchedMessages[:-1] fetchedMessages = fetchedMessages[:-1]
# Loop over the messages fetched # Loop over the messages fetched
for messages in fetchedMessages: for message in fetchedMessages:
# if the message is embeded already # if the message is embedded already
if messages.embeds: if message.embeds:
# set the embed message to the old embed object # set the embed message to the old embed object
embedMessage = messages.embeds[0] embedMessage = message.embeds[0]
# else # else
else: else:
# Create embed message object and set content to original # Create embed message object and set content to original
embedMessage = discord.Embed(description=messages.content) embedMessage = discord.Embed(description=message.content)
avatar_url = None avatar_url = None
if messages.author.avatar is not None: if message.author.display_avatar is not None:
avatar_url = messages.author.avatar.url avatar_url = str(message.author.display_avatar)
# set the embed message author to original author # set the embed message author to original author
embedMessage.set_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 message has attachments add them
if messages.attachments: if message.attachments:
for i in messages.attachments: for i in message.attachments:
embedMessage.set_image(url=i.proxy_url) embedMessage.set_image(url=i.proxy_url)
# Send to the desired channel # Send to the desired channel

View file

@ -1,8 +1,9 @@
import discord import discord
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Cog 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): class ModNote(Cog):

View file

@ -1,9 +1,11 @@
import asyncio import asyncio
import discord import discord
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Cog 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): class ModReact(Cog):

View file

@ -1,7 +1,8 @@
import config
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Cog 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): class ModReswitched(Cog):

View file

@ -1,12 +1,14 @@
import discord
import config
from datetime import datetime from datetime import datetime
import discord
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Cog from discord.ext.commands import Cog
from helpers.checks import check_if_staff
from helpers.robocronp import add_job from robocop_ng import config
from helpers.userlogs import userlog from robocop_ng.helpers.checks import check_if_staff
from helpers.restrictions import add_restriction 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): class ModTimed(Cog):

View file

@ -1,10 +1,12 @@
import json
import discord import discord
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Cog from discord.ext.commands import Cog
import config
import json from robocop_ng import config
from helpers.checks import check_if_staff from robocop_ng.helpers.checks import check_if_staff
from helpers.userlogs import get_userlog, set_userlog, userlog_event_types from robocop_ng.helpers.userlogs import get_userlog, set_userlog, userlog_event_types
class ModUserlog(Cog): class ModUserlog(Cog):
@ -233,7 +235,7 @@ class ModUserlog(Cog):
await ctx.send( await ctx.send(
f"user = {user_name}\n" f"user = {user_name}\n"
f"id = {user.id}\n" f"id = {user.id}\n"
f"avatar = {user.avatar_url}\n" f"avatar = {user.display_avatar}\n"
f"bot = {user.bot}\n" f"bot = {user.bot}\n"
f"created_at = {user.created_at}\n" f"created_at = {user.created_at}\n"
f"display_name = {display_name}\n" f"display_name = {display_name}\n"

View file

@ -1,8 +1,9 @@
import discord import discord
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Cog 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): class ModWatch(Cog):

View file

@ -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 aiohttp
import gidgethub.aiohttp import gidgethub.aiohttp
from helpers.checks import check_if_collaborator from discord import Embed
from helpers.checks import check_if_pin_channel 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): class Pin(Cog):

View file

@ -1,10 +1,12 @@
import discord
import asyncio import asyncio
import time import time
from datetime import datetime from datetime import datetime
import discord
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Cog 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): class Remind(Cog):

View file

@ -1,12 +1,14 @@
import config
import time import time
import discord
import traceback import traceback
import discord
from discord.ext import commands, tasks from discord.ext import commands, tasks
from discord.ext.commands import Cog from discord.ext.commands import Cog
from helpers.robocronp import get_crontab, delete_job
from helpers.restrictions import remove_restriction from robocop_ng import config
from helpers.checks import check_if_staff 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): class Robocronp(Cog):

View file

@ -1,12 +1,13 @@
import collections import collections
import json import json
import config
import os import os
import discord import discord
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Cog 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): class RyujinxReactionRoles(Cog):

View file

@ -1,9 +1,9 @@
import discord import discord
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Cog from discord.ext.commands import Cog
import config
import random from robocop_ng import config
from helpers.checks import check_if_staff from robocop_ng.helpers.checks import check_if_staff
class RyujinxVerification(Cog): class RyujinxVerification(Cog):

View file

@ -1,7 +1,8 @@
import config
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Cog 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): class SAR(Cog):

View file

@ -1,13 +1,15 @@
import asyncio
import hashlib
import itertools
import random
from inspect import cleandoc
import discord import discord
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Cog from discord.ext.commands import Cog
import asyncio
import config from robocop_ng import config
import random from robocop_ng.helpers.checks import check_if_staff
from inspect import cleandoc
import hashlib
import itertools
from helpers.checks import check_if_staff
class Verification(Cog): class Verification(Cog):

View file

@ -1,10 +1,12 @@
from discord.ext.commands import Cog
import re
import config
import secrets
import asyncio import asyncio
import base64 import base64
import hmac import hmac
import re
import secrets
from discord.ext.commands import Cog
from robocop_ng import config
class YubicoOTP(Cog): class YubicoOTP(Cog):

View file

@ -1,4 +1,4 @@
import config from robocop_ng import config
def check_if_staff(ctx): def check_if_staff(ctx):