Logging
This commit is contained in:
@@ -2,10 +2,14 @@ from PIL import Image
|
||||
from io import BytesIO
|
||||
import aiohttp
|
||||
import discord
|
||||
import logging
|
||||
|
||||
from redbot.core import commands, checks, Config
|
||||
|
||||
|
||||
log = logging.getLogger("red.aikaterna.antiphoneclapper")
|
||||
|
||||
|
||||
class AntiPhoneClapper(commands.Cog):
|
||||
"""This cog deletes bad GIFs that will crash phone clients."""
|
||||
|
||||
@@ -27,7 +31,10 @@ class AntiPhoneClapper(commands.Cog):
|
||||
|
||||
@nogif.command()
|
||||
async def watch(self, ctx, channel: discord.TextChannel):
|
||||
"""Add a channel to watch. Gifs that break mobile clients will be removed in these channels."""
|
||||
"""
|
||||
Add a channel to watch.
|
||||
Gif attachments that break mobile clients will be removed in these channels.
|
||||
"""
|
||||
channel_list = await self.config.guild(ctx.guild).watching()
|
||||
if channel.id not in channel_list:
|
||||
channel_list.append(channel.id)
|
||||
@@ -100,7 +107,7 @@ class AntiPhoneClapper(commands.Cog):
|
||||
return
|
||||
except discord.errors.Forbidden:
|
||||
await m.channel.send(f"Don't send GIFs that do that, {m.author.mention}")
|
||||
print(f"Failed to delete message ({m.id}) that contained phone killing gif")
|
||||
log.debug(f"Failed to delete message ({m.id}) that contained phone killing gif")
|
||||
return
|
||||
else:
|
||||
return
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import aiohttp
|
||||
from bs4 import BeautifulSoup
|
||||
import logging
|
||||
import re
|
||||
from redbot.core import commands
|
||||
|
||||
|
||||
log = logging.getLogger("red.aikaterna.dictionary")
|
||||
|
||||
|
||||
class Dictionary(commands.Cog):
|
||||
"""Word, yo
|
||||
Parts of this cog are adapted from the PyDictionary library."""
|
||||
@@ -19,9 +23,9 @@ class Dictionary(commands.Cog):
|
||||
try:
|
||||
async with self.session.request("GET", url) as response:
|
||||
return BeautifulSoup(await response.text(), "html.parser")
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return
|
||||
except Exception:
|
||||
log.error("Error fetching dictionary.py related webpage", exc_info=True)
|
||||
return None
|
||||
|
||||
@commands.command()
|
||||
async def antonym(self, ctx, *, word: str):
|
||||
@@ -37,6 +41,8 @@ class Dictionary(commands.Cog):
|
||||
|
||||
async def _antonym(self, ctx, word):
|
||||
data = await self._get_soup_object(f"http://www.thesaurus.com/browse/{word}")
|
||||
if not data:
|
||||
return await ctx.send("Error fetching data.")
|
||||
section = data.find_all("ul", {"class": "css-1lc0dpe et6tpn80"})
|
||||
try:
|
||||
section[1]
|
||||
@@ -74,10 +80,12 @@ class Dictionary(commands.Cog):
|
||||
await search_msg.edit(content=str_buffer)
|
||||
|
||||
async def _definition(self, ctx, word):
|
||||
html = await self._get_soup_object(f"http://wordnetweb.princeton.edu/perl/webwn?s={word}")
|
||||
types = html.findAll("h3")
|
||||
data = await self._get_soup_object(f"http://wordnetweb.princeton.edu/perl/webwn?s={word}")
|
||||
if not data:
|
||||
return await ctx.send("Error fetching data.")
|
||||
types = data.findAll("h3")
|
||||
length = len(types)
|
||||
lists = html.findAll("ul")
|
||||
lists = data.findAll("ul")
|
||||
out = {}
|
||||
if not lists:
|
||||
return
|
||||
@@ -95,6 +103,8 @@ class Dictionary(commands.Cog):
|
||||
|
||||
async def _synonym(self, ctx, word):
|
||||
data = await self._get_soup_object(f"http://www.thesaurus.com/browse/{word}")
|
||||
if not data:
|
||||
return await ctx.send("Error fetching data.")
|
||||
section = data.find_all("ul", {"class": "css-1lc0dpe et6tpn80"})
|
||||
try:
|
||||
section[1]
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import asyncio
|
||||
import datetime
|
||||
import discord
|
||||
import logging
|
||||
from redbot.core import Config, commands, checks, modlog
|
||||
from redbot.core.utils.chat_formatting import box, pagify
|
||||
|
||||
|
||||
log = logging.getLogger("red.aikaterna.dungeon")
|
||||
|
||||
|
||||
class Dungeon(commands.Cog):
|
||||
"""Auto-quarantine suspicious users."""
|
||||
|
||||
@@ -141,7 +145,7 @@ class Dungeon(commands.Cog):
|
||||
if not bypass_ids:
|
||||
msg += "None."
|
||||
for id in bypass_ids:
|
||||
msg += (f"{id}\n")
|
||||
msg += f"{id}\n"
|
||||
for page in pagify(msg, delims=["\n"], page_length=1000):
|
||||
await ctx.send(box(msg, lang="ini"))
|
||||
|
||||
@@ -416,7 +420,7 @@ class Dungeon(commands.Cog):
|
||||
if announce_channel:
|
||||
await channel_object.send(bypass_msg)
|
||||
else:
|
||||
print(f"dungeon.py: {bypass_msg}")
|
||||
log.debug(f"dungeon.py: {bypass_msg}")
|
||||
return
|
||||
|
||||
if (since_join.days < join_days) or (profile_toggle and default_avatar):
|
||||
@@ -437,7 +441,7 @@ class Dungeon(commands.Cog):
|
||||
f"I couldn't DM {member} ({member.id}) to let them know they've been banned, they've blocked me."
|
||||
)
|
||||
else:
|
||||
print(perm_msg)
|
||||
log.debug(perm_msg)
|
||||
return
|
||||
try:
|
||||
await member.guild.ban(
|
||||
@@ -449,16 +453,15 @@ class Dungeon(commands.Cog):
|
||||
f"I tried to auto-ban someone ({member}, {member.id}) but I don't have ban permissions."
|
||||
)
|
||||
else:
|
||||
print(perm_msg)
|
||||
log.debug(perm_msg)
|
||||
return
|
||||
|
||||
|
||||
if not mod_log:
|
||||
if announce_channel:
|
||||
msg = f"Auto-banned new user: \n**{member}** ({member.id})\n{self._dynamic_time(int(since_join.total_seconds()))} old account"
|
||||
return await channel_object.send(msg)
|
||||
else:
|
||||
print(perm_msg)
|
||||
log.debug(perm_msg)
|
||||
return
|
||||
else:
|
||||
try:
|
||||
@@ -472,9 +475,10 @@ class Dungeon(commands.Cog):
|
||||
until=None,
|
||||
channel=None,
|
||||
)
|
||||
except RuntimeError as e:
|
||||
print(
|
||||
f"dungeon.py error while autobanning user and attempting to create modlog entry: {e}\nIn guild: {member.guild.id}"
|
||||
except RuntimeError:
|
||||
log.error(
|
||||
f"dungeon.py error while autobanning user and attempting to create modlog entry in guild: {member.guild.id}",
|
||||
exc_info=True,
|
||||
)
|
||||
|
||||
if blacklist:
|
||||
@@ -498,7 +502,9 @@ class Dungeon(commands.Cog):
|
||||
"Someone suspicious joined but something went wrong. I need permissions to manage channels and manage roles."
|
||||
)
|
||||
else:
|
||||
print("dungeon.py: I need permissions to manage channels and manage roles.")
|
||||
log.info(
|
||||
f"dungeon.py: I need permissions to manage channels and manage roles in {member.guild.name} ({member.guild.id})."
|
||||
)
|
||||
return
|
||||
|
||||
msg = f"Auto-banished new user: \n**{member}** ({member.id})\n{self._dynamic_time(int(since_join.total_seconds()))} old account"
|
||||
|
||||
@@ -2,6 +2,7 @@ import asyncio
|
||||
import datetime
|
||||
import discord
|
||||
import inspect
|
||||
import logging
|
||||
import random
|
||||
import os
|
||||
import time
|
||||
@@ -12,6 +13,9 @@ from tabulate import tabulate
|
||||
from contextlib import suppress as sps
|
||||
|
||||
|
||||
log = logging.getLogger("red.aikaterna.tools")
|
||||
|
||||
|
||||
class Tools(commands.Cog):
|
||||
"""Mod and Admin tools."""
|
||||
|
||||
@@ -21,10 +25,10 @@ class Tools(commands.Cog):
|
||||
async def _Tools__error(self, ctx, error):
|
||||
if error.__cause__:
|
||||
cause = error.__cause__
|
||||
print(f"Tools Cog :: Error Occured ::\n{error}\n{cause}\n")
|
||||
log.info(f"Tools Cog :: Error Occured ::\n{error}\n{cause}\n")
|
||||
else:
|
||||
cause = error
|
||||
print(f"Tools Cog :: Error Occured :: \n{cause}\n")
|
||||
log.info(f"Tools Cog :: Error Occured :: \n{cause}\n")
|
||||
|
||||
@commands.guild_only()
|
||||
@checks.mod_or_permissions(manage_channels=True)
|
||||
|
||||
Reference in New Issue
Block a user