added max_posts feature to stop flooding IRC channel. all posts still go to the web front end

main
simp 2024-12-19 13:40:49 -05:00
parent 18960429ee
commit 0d227ee59c
1 changed files with 24 additions and 4 deletions

28
app.py
View File

@ -471,6 +471,7 @@ class Irc_bot:
self.new_user_time = irc_setting_update('new_user_greeting', 60, False, '', 0, True)[0]
self.throttle = irc_setting_update('throttle', 0, False, '', 0.25, True)[3]
self.channel_join = string_to_list(irc_setting_update('channel', 0, False, channel, 0, True)[2])
self.max_posts_per_pull = irc_setting_update('max_posts_per_pull', 10, False, '', 0, True)[0]
self.hostname = hostname
self.port = port
# self.http_port = http_tunnel
@ -686,8 +687,9 @@ class Irc_bot:
msg_f = f'''::{msg_url} @@@{msg_title}'''
(self.feed_dict[url])['posted'][i] = True
self.new_posts += 1
for item in self.channel_join:
send_irc_msg(self, msg_s, self.irc, item)
if i <= self.max_posts_per_pull:
for item in self.channel_join:
send_irc_msg(self, msg_s, self.irc, item)
save_feed_file(self, f'''{shorten}:{feed_url[url]['category']}''', msg_f, script_directory, feed_url[url]['category'])
save_feed_file(self, f'''{shorten}:{feed_url[url]['category']}''', msg_f, script_directory, 'all')
# if feed_url[url]['category'] == 'torrents':
@ -1084,6 +1086,7 @@ class Irc_bot:
settings_list = [
f'rss_feed_update <seconds (float)>',
f'max_posts <int>',
'main_channel <#channel>',
'throttle <seconds (float)>',
f'{Color.yellow}[info]{Color.normal} command without new <setting> gives current value. throttle is (s) between msg sends. main_channel is a list to join on connect, seperated by space or comma "#chan1 #chan2 #chan3'
@ -1165,9 +1168,27 @@ class Irc_bot:
msg.append(f"{admin_user} {com_err} not valid input, takes a float (seconds), 60s min.")
else:
msg.append(f"{admin_user} {Color.yellow}[Feed Update]{Color.normal} {str(self.rss_feed_update)}s")
elif 'max_posts' in line[4]:
reason, reason_msg = remaining_msg_irc(line, 4, False, False)
do_command = False
if len(line) >= 6:
m = 50
try:
new_setting = int(line[5])
if new_setting <= m:
msg.append(f"{admin_user} {com_msg} set max post per feed per update at {line[5]}")
self.max_posts_per_pull = new_setting
irc_setting_update('max_posts_per_pull', new_setting, False, '', 0, False)
else:
msg.append(f"{admin_user} {com_err} too many {m} max.")
except Exception as e:
print(e)
msg.append(f"{admin_user} {com_err} not valid input, takes an int {str(m)} max.")
else:
msg.append(f"{admin_user} {Color.yellow}[Max posts per pull]{Color.normal} {str(self.max_posts_per_pull)}")
print(str(len(line)))
elif 'check' in line[4]:
reason, reason_msg = remaining_msg_irc(line, 4, False, False)
do_command = False
@ -1218,7 +1239,6 @@ class Irc_bot:
else:
msg.append(f"{admin_user} {Color.yellow}[error]{Color.normal} enter a nick")
print(str(len(line)))
elif 'ignore' in line[4] or 'unignore' in line[4]:
reason, reason_msg = remaining_msg_irc(line, 5, False, True)
do_command = True