Skip to content

[ImgBot] Optimize images #2

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

Merged
merged 2 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cogs/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ async def _beerparty(
):
reason = ("\nReason: " + reason) if reason else ""
msg = await ctx.send(
"Open invite to beerparty! React with 🍻 to join!" + reason
)
f"Open invite to beerparty! React with 🍻 to join!{reason}"
)
await msg.add_reaction("\U0001f37b")
await asyncio.sleep(60)
msg = await ctx.channel.fetch_message(msg.id)
Expand Down
5 changes: 2 additions & 3 deletions cogs/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ async def _source(
src = type(self.bot.help_command)
module = src.__module__
filename = inspect.getsourcefile(src)
help_command = self.bot.get_command("help")
if help_command:
if help_command := self.bot.get_command("help"):
embed.description = help_command.help.format(prefix=ctx.prefix)
else:
obj = self.bot.get_command(command.replace(".", " "))
Expand Down Expand Up @@ -97,7 +96,7 @@ async def define(self, ctx: commands.Context[CodingBot], *, word: str):
return await ctx.send(f"Could not find definition for `{word}`")
definition = definition[0]
embed = discord.Embed(
title="Definition of {}".format(word),
title=f"Definition of {word}",
description=f"**Meaning**: {definition.meaning}\n",
color=discord.Color.random(),
)
Expand Down
69 changes: 30 additions & 39 deletions cogs/helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import asyncio
import contextlib
import datetime
from io import BytesIO
from typing import TYPE_CHECKING, Any, Optional
Expand Down Expand Up @@ -53,9 +54,7 @@ async def cog_check(self, ctx: commands.Context[CodingBot]) -> bool:

official_helper_role = ctx.guild.get_role(OFFICIAL_HELPER_ROLE_ID)

if official_helper_role not in ctx.author.roles:
return False
return True
return official_helper_role in ctx.author.roles

async def capture_evidence(
self, ctx: commands.Context[CodingBot]
Expand All @@ -80,28 +79,27 @@ async def capture_evidence(
)
view_touched = not (await view.wait())
evidence_byts = None
if view_touched:
if view.confirmed:
initial_mess = await ctx.author.send(
"Please send the evidence in the form of an attachment."
if view_touched and view.confirmed:
initial_mess = await ctx.author.send(
"Please send the evidence in the form of an attachment."
)
try:
wait_mess = await self.bot.wait_for(
"message",
check=lambda m: m.author == ctx.author
and m.channel == initial_mess.channel
and m.attachments
and not m.guild,
timeout=60,
)
try:
wait_mess = await self.bot.wait_for(
"message",
check=lambda m: m.author == ctx.author
and m.channel == initial_mess.channel
and m.attachments
and not m.guild,
timeout=60,
)
except asyncio.TimeoutError:
await initial_mess.delete()
await ctx.author.send(
"You didn't send any evidence in time. "
"Proceeding with the ban without evidence."
)
else:
evidence_byts = await wait_mess.attachments[0].read()
except asyncio.TimeoutError:
await initial_mess.delete()
await ctx.author.send(
"You didn't send any evidence in time. "
"Proceeding with the ban without evidence."
)
else:
evidence_byts = await wait_mess.attachments[0].read()
return evidence_byts

async def log(
Expand Down Expand Up @@ -168,15 +166,15 @@ async def log(
raise undo_action

action_string = (
action_info["action"] if not undo else action_info["undo_action"]
action_info["undo_action"] if undo else action_info["action"]
)
icon = action_info["icon"] if not undo else action_info["undo_icon"]
icon = action_info["undo_icon"] if undo else action_info["icon"]
color = discord.Color.green() if undo else action_info.get("color")

embed = discord.Embed(color=color, timestamp=discord.utils.utcnow())

embed.description = "{} **Action:** {}\n**Reason:** {}\n".format(
icon, action_string.title(), reason
embed.description = (
f"{icon} **Action:** {action_string.title()}\n**Reason:** {reason}\n"
)
if duration:
embed.description += "**Duration:** {}\n".format(
Expand Down Expand Up @@ -272,12 +270,9 @@ async def help_warnings(

for i, warning in enumerate(records, 1):
helper = ctx.guild.get_member(warning.helper_id)
if helper:
helper = helper.mention
else:
helper = "Unknown"
helper = helper.mention if helper else "Unknown"
embed.add_field(
name="`{}.` Reason: {}".format(i, warning.reason),
name=f"`{i}.` Reason: {warning.reason}",
value=f"Issued by: {helper} - <t:{int(warning.date)}:f>",
inline=False,
)
Expand Down Expand Up @@ -357,10 +352,8 @@ async def help_ban(
await member.add_roles(help_ban_role)

await self.bot.reply(ctx, f"help-banned {member.mention} with reason: {reason}")
try:
with contextlib.suppress(discord.Forbidden):
await member.send(f"You have been help-banned with reason: {reason}")
except discord.Forbidden:
pass

@helper.command(name="unban")
async def help_unban(
Expand All @@ -383,11 +376,9 @@ async def help_unban(
await member.remove_roles(help_ban_role)

await self.bot.reply(ctx, f"help-unbanned {member.mention}")
try:
with contextlib.suppress(discord.Forbidden):
await member.send("You have been help-unbanned")
await self.log(action="ban", undo=True, member=member, helper=ctx.author)
except discord.Forbidden:
pass

@helper.command(name="verify")
async def help_verify(
Expand Down
100 changes: 49 additions & 51 deletions cogs/listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import re
import sys
import asyncio
import contextlib
import traceback
from datetime import datetime
from typing import TYPE_CHECKING

import discord
from datetime import timezone
from discord.ext import commands
from ext.consts import TCR_STAFF_ROLE_ID
from ext.helpers import check_invite
Expand Down Expand Up @@ -51,17 +53,16 @@ async def thank_message(self, message: discord.Message):
if message.author.bot or not message.guild:
return

if message.channel.category.id == 754710748353265745:
if (
"thanks" in message.content.lower()
or "thank you" in message.content.lower()
or "thx" in message.content.lower()
or "thnx" in message.content.lower()
):
await message.reply(
"If someone has helped you, "
"you can thank them by using the `.thank` command."
)
if message.channel.category.id == 754710748353265745 and (
"thanks" in message.content.lower()
or "thank you" in message.content.lower()
or "thx" in message.content.lower()
or "thnx" in message.content.lower()
):
await message.reply(
"If someone has helped you, "
"you can thank them by using the `.thank` command."
)

@commands.Cog.listener("on_message")
async def afk_user_messaage(self, message: discord.Message):
Expand All @@ -81,39 +82,36 @@ async def afk_user_messaage(self, message: discord.Message):
record = self.bot.afk_cache.get(message.guild.id)
if record:
record = record.get(message.author.id)
if record:
_, time = record
if (datetime.utcnow() - datetime.utcfromtimestamp(time)).seconds < 30:
return
await self.bot.conn.delete_record(
"afk",
table="afk",
where=("user_id",),
values=(message.author.id,),
)
try:
if "[AFK]" in message.author.display_name:
name = message.author.display_name.split(" ")[1:]
await message.author.edit(nick=" ".join(name))
except (discord.HTTPException, discord.Forbidden):
pass

staff_role = message.guild.get_role(795145820210462771)
if staff_role and staff_role in message.author.roles:
on_pat_staff = message.guild.get_role(726441123966484600)
try:
await message.author.add_roles(on_pat_staff)
except (discord.Forbidden, discord.HTTPException):
pass
del self.bot.afk_cache[message.guild.id][message.author.id]
em = discord.Embed(
description=f"{message.author.mention} Welcome back, "
"I removed your AFK!",
color=discord.Color.dark_gold(),
)
msg = await message.reply(embed=em)
await asyncio.sleep(5)
await msg.delete()
if record:
_, time = record
if (
datetime.now(timezone.utc) - datetime.utcfromtimestamp(time)
).seconds < 30:
return
await self.bot.conn.delete_record(
"afk",
table="afk",
where=("user_id",),
values=(message.author.id,),
)
with contextlib.suppress(discord.HTTPException, discord.Forbidden):
if "[AFK]" in message.author.display_name:
name = message.author.display_name.split(" ")[1:]
await message.author.edit(nick=" ".join(name))
staff_role = message.guild.get_role(795145820210462771)
if staff_role and staff_role in message.author.roles:
on_pat_staff = message.guild.get_role(726441123966484600)
with contextlib.suppress(discord.Forbidden, discord.HTTPException):
await message.author.add_roles(on_pat_staff)
del self.bot.afk_cache[message.guild.id][message.author.id]
em = discord.Embed(
description=f"{message.author.mention} Welcome back, "
"I removed your AFK!",
color=discord.Color.dark_gold(),
)
msg = await message.reply(embed=em)
await asyncio.sleep(5)
await msg.delete()

@commands.Cog.listener("on_message")
async def user_mentioned(self, message: discord.Message):
Expand Down Expand Up @@ -191,10 +189,7 @@ async def on_command_error(self, ctx: commands.Context, error: Exception) -> Non
)
return await ctx.send(embed=embed, ephemeral=True)
else:
print(
"Ignoring exception in command {}:".format(ctx.command),
file=sys.stderr,
)
print(f"Ignoring exception in command {ctx.command}:", file=sys.stderr)
traceback.print_exception(
type(error), error, error.__traceback__, file=sys.stderr
)
Expand All @@ -209,9 +204,12 @@ async def track_sent_message(self, message: discord.Message):
return

values = [message.author.id, message.guild.id, 1, 1]
columns = ["user_id", "guild_id", "message_count"]

columns.append(status := message.author.status.name)
columns = [
"user_id",
"guild_id",
"message_count",
status := message.author.status.name,
]

staff_role = message.guild.get_role(TCR_STAFF_ROLE_ID)
if staff_role and staff_role in message.author.roles: # type: ignore
Expand Down
19 changes: 7 additions & 12 deletions cogs/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import TYPE_CHECKING, Optional

import button_paginator as pg
import contextlib
import discord
from discord.ext import commands
from ext.helpers import Spotify, grouper, ordinal_suffix_of
Expand Down Expand Up @@ -80,10 +81,8 @@ async def afk(
) # "on_patrol_staff" role

if staff_role in member.roles:
try:
await member.remove_roles(on_pat_staff)
except (discord.Forbidden, discord.HTTPException):
pass
with contextlib.suppress(discord.Forbidden, discord.HTTPException):
await member.remove_roles(on_pat_staff)
if ctx.guild.id not in self.bot.afk_cache:
self.bot.afk_cache[ctx.guild.id] = {}
if member.id not in self.bot.afk_cache.get(ctx.guild.id):
Expand All @@ -93,10 +92,8 @@ async def afk(
values=(member.id, reason, int(ctx.message.created_at.timestamp())),
columns=["user_id", "reason", "afk_time"],
)
try:
with contextlib.suppress(Exception):
await member.edit(nick=f"[AFK] {member.display_name}")
except Exception:
pass
try:
self.bot.afk_cache[ctx.guild.id][member.id] = (
reason,
Expand Down Expand Up @@ -400,14 +397,12 @@ async def trainee_list(self, ctx: commands.Context[CodingBot]):
"""

trainee_role = ctx.guild.get_role(729537643951554583) # type: ignore
members = trainee_role.members

if not members:
trainees = "No trainees yet."
else:
if members := trainee_role.members:
trainees = "\n".join(
f"{i}. {member.mention}" for i, member in enumerate(members, 1)
)
else:
trainees = "No trainees yet."
embed = discord.Embed(
title="Trainees list", description=trainees, color=discord.Color.blue()
)
Expand Down
Loading