Skip to content

Commit 91c37a2

Browse files
committed
fix modmail no timeout
1 parent 3b4c606 commit 91c37a2

1 file changed

Lines changed: 2 additions & 51 deletions

File tree

cogs/modmail.py

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Modmail cog: Users DM the bot, messages are forwarded to a modmail channel. Mods can reply from the channel.
33
"""
44
import discord
5-
from discord.ext import commands, tasks
5+
from discord.ext import commands
66
from discord import app_commands
77
from utils.config import Config
88
from typing import Optional, Dict, Any, Union
@@ -29,7 +29,6 @@ def __init__(self, bot: commands.Bot, config: Config):
2929
self.bot = bot
3030
self.config = config
3131
self.modmail_channel_id: Optional[int] = getattr(config, 'modmail_channel_id', None)
32-
self.RESET_DELAY_SECONDS: int = getattr(config, 'modmail_reset_seconds', 600)
3332
self._dm_semaphore: asyncio.Semaphore = asyncio.Semaphore(10) # Simultaneous DMs
3433
self._dm_channel_cache: Dict[int, discord.DMChannel] = {}
3534
self._webhook: Optional[discord.Webhook] = None
@@ -45,10 +44,9 @@ async def cog_load(self):
4544
await self._load_sessions_from_file()
4645
except Exception:
4746
logger.exception("modmail: failed to load persisted sessions")
48-
self.cleanup_inactive_sessions.start()
4947

5048
def cog_unload(self):
51-
self.cleanup_inactive_sessions.cancel()
49+
pass
5250

5351
async def _send_with_retry(self, send_func, *args, max_retries=3, **kwargs):
5452
for attempt in range(max_retries):
@@ -336,53 +334,6 @@ async def close_session(self, ctx):
336334

337335
await ctx.channel.edit(name=new_name, archived=True, locked=True)
338336

339-
@tasks.loop(minutes=1)
340-
async def cleanup_inactive_sessions(self):
341-
now = datetime.utcnow()
342-
to_remove = []
343-
344-
for user_id, session in self.modmail_sessions.items():
345-
last_activity_str = session.get('last_activity')
346-
if not last_activity_str:
347-
continue
348-
349-
last_activity = datetime.fromisoformat(last_activity_str)
350-
if (now - last_activity).total_seconds() > self.RESET_DELAY_SECONDS:
351-
to_remove.append(user_id)
352-
353-
for user_id in to_remove:
354-
session = self.modmail_sessions.pop(user_id)
355-
thread_id = session.get('thread_id')
356-
357-
# Close thread
358-
if self.modmail_channel_id:
359-
channel = self.bot.get_channel(self.modmail_channel_id)
360-
if channel and isinstance(channel, discord.TextChannel):
361-
thread = None
362-
if thread_id:
363-
thread = channel.get_thread(int(thread_id))
364-
if thread:
365-
try:
366-
await thread.send("Session timed out due to inactivity.")
367-
await thread.edit(archived=True, locked=True)
368-
except:
369-
pass
370-
371-
# Notify User
372-
user = self.bot.get_user(user_id)
373-
if user:
374-
try:
375-
await user.send(embed=discord.Embed(
376-
title="Session Closed",
377-
description="Modmail session timed out due to inactivity.",
378-
color=discord.Color.default()
379-
))
380-
except:
381-
pass
382-
383-
if to_remove:
384-
await self._persist_sessions_to_file()
385-
386337
@commands.command(name="set_modmail_channel")
387338
@commands.has_permissions(administrator=True)
388339
async def set_modmail_channel(self, ctx: commands.Context, channel: Optional[discord.TextChannel] = None):

0 commit comments

Comments
 (0)