untested commit (migrating server hosting machine)
This commit is contained in:
parent
f4c56d94c3
commit
eb55d0185e
48
bot.py
48
bot.py
@ -6,10 +6,7 @@ import re
|
||||
privmsg_channel_re = re.compile(r"PRIVMSG (#*\w+)")
|
||||
nick_re = re.compile(r"^:([^!]*)!")
|
||||
|
||||
# timeout = 86400 # 24 hours
|
||||
# these very low values are for testing
|
||||
timeout = 15
|
||||
messages_within_timeout = 5
|
||||
default_timeout = 43200 # 12 hours in seconds
|
||||
host = "localhost"
|
||||
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"
|
||||
@ -66,9 +63,6 @@ class IRCBot():
|
||||
elif isinstance(content, str):
|
||||
self.send_raw_line(f"PRIVMSG {channel} :{content}")
|
||||
|
||||
def help(_, __):
|
||||
return helptext
|
||||
|
||||
def invite(self, _, arguments):
|
||||
if not arguments:
|
||||
return helptext_short
|
||||
@ -102,18 +96,18 @@ class IRCBot():
|
||||
def set_time(self, channel, this_time):
|
||||
self.state["times"][channel] = this_time
|
||||
|
||||
def counter(self, channel):
|
||||
def set_timeout(self, channel, arguments):
|
||||
timeout = int(timeout_hours * 60 * 60)
|
||||
self.state["timeouts"][channel] = timeout
|
||||
self.write_state()
|
||||
return f"channel timeout set to {timeout_hours} hours"
|
||||
|
||||
def get_timeout(self, channel):
|
||||
try:
|
||||
self.state["counts"][channel] += 1
|
||||
value = self.state["counts"][channel]
|
||||
self.state["timeouts"][channel]
|
||||
except KeyError:
|
||||
value = self.state["counts"][channel] = 1
|
||||
self.write_state()
|
||||
return value
|
||||
|
||||
def reset_count(self, channel):
|
||||
self.state["counts"][channel] = 0
|
||||
self.write_state()
|
||||
self.state["timeouts"][channel] = default_timeout
|
||||
self.write_state()
|
||||
|
||||
def command_loop(self):
|
||||
while True:
|
||||
@ -162,20 +156,14 @@ class IRCBot():
|
||||
else:
|
||||
if channel in ("#tildetown", "#bots"):
|
||||
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__":
|
||||
bot = IRCBot()
|
||||
|
@ -3,6 +3,7 @@
|
||||
"realname": "a bot by ~nebula",
|
||||
"channels": ["#bots"],
|
||||
"times": {},
|
||||
"counts": {}
|
||||
"counts": {},
|
||||
"timeouts": {}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user