Skip to content
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
13 changes: 10 additions & 3 deletions activitylog/activitylog.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,11 @@ async def get_audit_entry(
cached_entries = self.audit_logs[guild.id]
# it seems that cached entries wont contain the updated audit event right when it happens, it seems to fire after the event handler that is in question, may help with high traffic bots though
for entry in cached_entries:
if all(cond(entry) for cond in conditions):
return entry
if entry is not None:
if all(cond(entry) for cond in conditions):
return entry

# fallback to look at audit log for the guild
# fallback to look at audit log for qthe guild
# print("firing get_audit_entry")
# print(len(conditions))
if self.cache["check_audit"]:
Expand Down Expand Up @@ -3210,6 +3211,12 @@ async def on_thread_create(self, thread: discord.Thread):
if not self.should_log(thread.guild):
return

# try to join the thread so we can log
try:
await thread.join()
except:
pass

audit_entry = await self.get_audit_entry(
thread.guild,
lambda e: e.action == discord.AuditLogAction.thread_create,
Expand Down
12 changes: 6 additions & 6 deletions chatbotassistant/chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,11 @@ def format_response(self, content: str, guild: discord.Guild):
A string where emoji names and user display names (with or without
leading '@') become proper Discord mentions.
"""
emoji_map: Dict[str, str] = {emoji.name.lower(): str(emoji) for emoji in guild.emojis}
# allow pulling for multiple guilds
emoji_map: Dict[str, str] = {}
for e_guild in self.bot.guilds:
for emoji in e_guild.emojis:
emoji_map[emoji.name.lower()] = str(emoji)
# user_map: Dict[str, str] = {member.display_name.lower(): member.mention for member in guild.members}

# remove possible system bot name prefix n the response:
Expand Down Expand Up @@ -2342,10 +2346,6 @@ async def on_message(self, message: discord.Message):
)
)

# TODO: for testing, remove
if channel.id not in [1367715420081229855, 532724833981562890, 703281764923211846]:
return

lock = self.channel_lock[channel.id]
# if the lock is already taken, end after updating history
if lock.locked():
Expand Down Expand Up @@ -2397,7 +2397,7 @@ async def on_message(self, message: discord.Message):
except:
pass
else:
msg = await channel.send(response)
msg = await channel.send(response, reference=message, mention_author=False)

@commands.Cog.listener()
async def on_reaction_add(self, reaction: discord.Reaction, member: Union[discord.Member, discord.User]):
Expand Down
18 changes: 9 additions & 9 deletions mayhemmaker/mayhemmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,22 +210,22 @@ async def check_cooldown(
target_level: int = await self.level_cog.get_level(target)
# check level cooldowns, default to global cooldowns otherwise
lvl_usage_cooldowns = (await self.config.guild(guild).level_integration_usage_cooldowns())[action]
lvls = sorted(list(lvl_usage_cooldowns.keys()))
lvls = sorted([int(k) for k in lvl_usage_cooldowns.keys()])
member_usage_cooldown = 0
if lvl_usage_cooldowns:
member_usage_cooldown = bisect.bisect_left(lvls, str(member_level))
member_usage_cooldown = bisect.bisect_left(lvls, member_level)
if member_usage_cooldown != len(
lvl_usage_cooldowns
): # if false then member has a higher level then configured
member_usage_cooldown = lvl_usage_cooldowns[lvls[member_usage_cooldown]]
member_usage_cooldown = lvl_usage_cooldowns[str(lvls[member_usage_cooldown])]

lvl_applied_cooldowns = (await self.config.guild(guild).level_integration_applied_cooldowns())[action]
lvls = sorted(list(lvl_applied_cooldowns.keys()))
lvls = sorted([int(k) for k in lvl_applied_cooldowns.keys()])
target_applied_cooldown = 0
if lvl_applied_cooldowns:
target_applied_cooldown = bisect.bisect_left(lvls, str(target_level))
target_applied_cooldown = bisect.bisect_left(lvls, target_level)
if target_applied_cooldown != len(lvl_applied_cooldowns):
target_applied_cooldown = lvl_applied_cooldowns[lvls[target_applied_cooldown]]
target_applied_cooldown = lvl_applied_cooldowns[str(lvls[target_applied_cooldown])]

if member_usage_cooldown:
usage_cooldown = member_usage_cooldown
Expand Down Expand Up @@ -292,12 +292,12 @@ async def apply_mayhem(
max_duration = await self.config.guild(member.guild).max_duration()
if self.level_cog is not None:
lvl_maxduration = await self.config.guild(member.guild).level_integration_max_duration()
lvls = sorted(list(lvl_maxduration.keys()))
lvls = sorted([int(k) for k in lvl_maxduration.keys()])
member_level = await self.level_cog.get_level(ctx.author)
if lvl_maxduration:
idx = bisect.bisect_left(lvls, str(member_level))
idx = bisect.bisect_left(lvls, member_level)
if idx != len(lvl_maxduration):
max_duration = lvl_maxduration[lvls[idx]]
max_duration = lvl_maxduration[str(lvls[idx])]

if action != "shut":
time = parse_timedelta(duration)
Expand Down