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 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

View file

@ -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):

View file

@ -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)

View file

@ -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):

View file

@ -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")

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
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):

View file

@ -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):

View file

@ -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):
"""

View file

@ -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):
"""

View file

@ -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):

View file

@ -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(
(

View file

@ -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)

View file

@ -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):

View file

@ -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

View file

@ -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):

View file

@ -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):

View file

@ -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):

View file

@ -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):

View file

@ -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"

View file

@ -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):

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 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):

View file

@ -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):

View file

@ -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):

View file

@ -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):

View file

@ -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):

View file

@ -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):

View file

@ -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):

View file

@ -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):

View file

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