Update fun.py

Added shorter !cc deletion message to solve message overflow error
This commit is contained in:
Cal Corum 2023-02-21 11:36:12 -06:00
parent 1317783063
commit 50022f6979

View File

@ -1,3 +1,4 @@
import copy
import math
from helpers import *
@ -86,7 +87,7 @@ class Fun(commands.Cog):
else:
del_notifs[owner.id]['commands'].append((x.name, x.message))
# x.delete_instance()
x.delete_instance()
del_counter += 1
elif x.last_used + timedelta(days=60) < now and (x.sent_warns is None or x.sent_warns == 0):
@ -113,18 +114,40 @@ class Fun(commands.Cog):
plural = len(del_notifs[member]["commands"]) > 1
msg_content = f'Yo, it\'s cleanup time. I am deleting the following custom ' \
f'command{"s" if plural else ""}:\n\n'
short_msg_content = copy.deepcopy(msg_content)
for x in del_notifs[member]["commands"]:
msg_content += f'`!cc {x[0]}` - {x[1]}\n'
await del_notifs[member]['member'].send(msg_content)
short_msg_content += f'`!cc {x[0]}`\n'
try:
await del_notifs[member]['member'].send(msg_content)
except Exception as e:
logging.error(f'fun daily_check - could not send deletion message to {del_notifs[member]["member"]} '
f'/ trying short_msg')
try:
await del_notifs[member]['member'].send(short_msg_content)
except Exception as e:
logging.error(f'fun daily_check - still could not send deletion message')
for member in warn_notifs:
plural = len(warn_notifs[member]["commands"]) > 1
msg_content = f'Heads up, the following custom ' \
f'command{"s" if plural else ""} will be deleted next month if ' \
f'{"they are" if plural else "it is"} not used:\n\n'
short_msg_content = copy.deepcopy(msg_content)
for x in warn_notifs[member]["commands"]:
msg_content += f'`!cc {x[0]}` - {x[1]}\n'
await warn_notifs[member]['member'].send(msg_content)
short_msg_content += f'`!cc {x[0]}`\n'
try:
await warn_notifs[member]['member'].send(msg_content)
except Exception as e:
logging.error(f'fun daily_check - could not send warn message to {warn_notifs[member]["member"]} '
f'/ trying short_msg')
try:
await warn_notifs[member]['member'].send(short_msg_content)
except Exception as e:
logging.error(f'fun daily_check - still could not send warn message')
logging.info(f'Deleted {del_counter} commands; sent deletion notifications to {len(del_notifs)} users; '
f'sent warnings to {len(warn_notifs)} users')