update spam plugin to remove bans
This commit is contained in:
parent
5e78385a7e
commit
5910454cbf
@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""
|
"""
|
||||||
IRC3 Anti-Spam Plugin with Auto-Kick and Auto-Ban
|
IRC3 Anti-Spam Plugin with Auto-Kick, Auto-Ban, and Auto-Unban
|
||||||
|
|
||||||
This plugin automatically detects and mitigates spam in IRC channels
|
This plugin automatically detects and mitigates spam in IRC channels
|
||||||
by monitoring messages for:
|
by monitoring messages for:
|
||||||
@ -10,12 +10,12 @@ by monitoring messages for:
|
|||||||
|
|
||||||
Actions:
|
Actions:
|
||||||
- **1st and 2nd offense**: User gets kicked.
|
- **1st and 2nd offense**: User gets kicked.
|
||||||
- **3rd offense within 5 minutes**: User gets banned.
|
- **3rd offense within 5 minutes**: User gets banned and automatically unbanned after 5 minutes.
|
||||||
|
|
||||||
Features:
|
Features:
|
||||||
- Uses a dynamic WHO query to verify user modes before action.
|
- Uses a dynamic WHO query to verify user modes before action.
|
||||||
- Configurable limits for spam detection (via `antispam` settings).
|
- Configurable limits for spam detection (via `antispam` settings).
|
||||||
- Periodic cleanup of inactive users every minute.
|
- Periodic cleanup of inactive users and expired bans every minute.
|
||||||
|
|
||||||
Author: [Your Name]
|
Author: [Your Name]
|
||||||
"""
|
"""
|
||||||
@ -50,8 +50,9 @@ class AntiSpam:
|
|||||||
'mentions': deque(maxlen=int(self.config.get('mention_limit', 2)))
|
'mentions': deque(maxlen=int(self.config.get('mention_limit', 2)))
|
||||||
})
|
})
|
||||||
self.kick_history = defaultdict(deque) # Track kick timestamps per user
|
self.kick_history = defaultdict(deque) # Track kick timestamps per user
|
||||||
|
self.active_bans = [] # Track active bans with timestamps for auto-removal
|
||||||
|
|
||||||
self.exclude_list = ['ZodBot','g1mp','scroll','WILDWEST','CANCER','aibird'] # Bots that should be ignored
|
self.exclude_list = ['ZodBot','g1mp','scroll','WILDWEST','CANCER','aibird'] # Bots to ignore
|
||||||
self.service_name = self.config.get('service_name', 'ChanServ')
|
self.service_name = self.config.get('service_name', 'ChanServ')
|
||||||
|
|
||||||
self.who_channel = WhoChannel(bot) # WHO query for user modes
|
self.who_channel = WhoChannel(bot) # WHO query for user modes
|
||||||
@ -175,6 +176,13 @@ class AntiSpam:
|
|||||||
ban_mask = f'*!{mask.host}'
|
ban_mask = f'*!{mask.host}'
|
||||||
self.bot.send(f"MODE {channel} +b {ban_mask}")
|
self.bot.send(f"MODE {channel} +b {ban_mask}")
|
||||||
|
|
||||||
|
# Record ban for auto-removal
|
||||||
|
self.active_bans.append({
|
||||||
|
'ban_mask': ban_mask,
|
||||||
|
'channel': channel,
|
||||||
|
'timestamp': current_time
|
||||||
|
})
|
||||||
|
|
||||||
self.bot.privmsg(
|
self.bot.privmsg(
|
||||||
self.service_name,
|
self.service_name,
|
||||||
f"KICK {channel} {nick} :Banned for repeated spamming"
|
f"KICK {channel} {nick} :Banned for repeated spamming"
|
||||||
@ -208,6 +216,17 @@ class AntiSpam:
|
|||||||
}
|
}
|
||||||
self.bot.log.info("Cleaned up old spam records.")
|
self.bot.log.info("Cleaned up old spam records.")
|
||||||
|
|
||||||
|
@cron('* * * * *')
|
||||||
|
def remove_expired_bans(self):
|
||||||
|
"""Remove bans that are older than 5 minutes."""
|
||||||
|
current_time = time.time()
|
||||||
|
expired_bans = [ban for ban in self.active_bans if current_time - ban['timestamp'] >= 300]
|
||||||
|
for ban in expired_bans:
|
||||||
|
self.bot.send(f"MODE {ban['channel']} -b {ban['ban_mask']}")
|
||||||
|
self.bot.log.info(f"Auto-removed ban {ban['ban_mask']} from {ban['channel']} after 5 minutes.")
|
||||||
|
# Update active_bans to exclude expired ones
|
||||||
|
self.active_bans = [ban for ban in self.active_bans if current_time - ban['timestamp'] < 300]
|
||||||
|
|
||||||
def connection_made(self):
|
def connection_made(self):
|
||||||
"""Initialize when bot connects."""
|
"""Initialize when bot connects."""
|
||||||
self.bot.log.info("AntiSpam plugin loaded with automated kick-to-ban escalation.")
|
self.bot.log.info("AntiSpam plugin loaded with automated kick-to-ban escalation and auto-unban.")
|
Loading…
Reference in New Issue
Block a user