untested commit (migrating server hosting machine)

This commit is contained in:
= 2025-04-13 20:33:08 +00:00
parent f4c56d94c3
commit eb55d0185e
2 changed files with 20 additions and 31 deletions

46
bot.py
View File

@ -6,10 +6,7 @@ import re
privmsg_channel_re = re.compile(r"PRIVMSG (#*\w+)") privmsg_channel_re = re.compile(r"PRIVMSG (#*\w+)")
nick_re = re.compile(r"^:([^!]*)!") nick_re = re.compile(r"^:([^!]*)!")
# timeout = 86400 # 24 hours default_timeout = 43200 # 12 hours in seconds
# these very low values are for testing
timeout = 15
messages_within_timeout = 5
host = "localhost" host = "localhost"
port = 6667 port = 6667
helptext = "i am a bot by ~nebula. i try to make it easier for users to discover new and more obscure channels on irc. instructions for use (or to block me from showing messages in your client) are available at https://git.tilde.town/nebula/chatterbot" helptext = "i am a bot by ~nebula. i try to make it easier for users to discover new and more obscure channels on irc. instructions for use (or to block me from showing messages in your client) are available at https://git.tilde.town/nebula/chatterbot"
@ -66,9 +63,6 @@ class IRCBot():
elif isinstance(content, str): elif isinstance(content, str):
self.send_raw_line(f"PRIVMSG {channel} :{content}") self.send_raw_line(f"PRIVMSG {channel} :{content}")
def help(_, __):
return helptext
def invite(self, _, arguments): def invite(self, _, arguments):
if not arguments: if not arguments:
return helptext_short return helptext_short
@ -102,17 +96,17 @@ class IRCBot():
def set_time(self, channel, this_time): def set_time(self, channel, this_time):
self.state["times"][channel] = this_time self.state["times"][channel] = this_time
def counter(self, channel): def set_timeout(self, channel, arguments):
try: timeout = int(timeout_hours * 60 * 60)
self.state["counts"][channel] += 1 self.state["timeouts"][channel] = timeout
value = self.state["counts"][channel]
except KeyError:
value = self.state["counts"][channel] = 1
self.write_state() self.write_state()
return value return f"channel timeout set to {timeout_hours} hours"
def reset_count(self, channel): def get_timeout(self, channel):
self.state["counts"][channel] = 0 try:
self.state["timeouts"][channel]
except KeyError:
self.state["timeouts"][channel] = default_timeout
self.write_state() self.write_state()
def command_loop(self): def command_loop(self):
@ -162,20 +156,14 @@ class IRCBot():
else: else:
if channel in ("#tildetown", "#bots"): if channel in ("#tildetown", "#bots"):
continue continue
# i have not figured out this part yet channel_time = self.check_time(channel)
now = time()
channel_timeout = self.get_timeout(channel)
delta = now - channel_time
if delta > channel_timeout:
self.send("#bots", f"i hear activity in {channel}...")
self.set_time(channel, now)
# channel_time = self.check_time(channel)
# now = time()
# count = self.counter(channel)
# delta = now - channel_time
# if delta > timeout:
# if count < messages_within_timeout:
# self.send("#bots", f"i hear activity in {channel}...")
# self.reset_count(channel)
# elif and channel_time :
# self.reset_count
# self.set_time(channel, now)
if __name__ == "__main__": if __name__ == "__main__":
bot = IRCBot() bot = IRCBot()

View File

@ -3,6 +3,7 @@
"realname": "a bot by ~nebula", "realname": "a bot by ~nebula",
"channels": ["#bots"], "channels": ["#bots"],
"times": {}, "times": {},
"counts": {} "counts": {},
"timeouts": {}
} }