Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion lib/pyborg/pyborg-irc.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class ModIRC(SingleServerIRCBot):
"ignore": "Owner command. Usage: !ignore [nick1 [nick2 [...]]]\nIgnore one or more nicknames. Without arguments it lists ignored nicknames",
"unignore": "Owner command. Usage: !unignore nick1 [nick2 [...]]\nUnignores one or more nicknames",
"replyrate": "Owner command. Usage: !replyrate [rate%]\nSet rate of bot replies to rate%. Without arguments (not an owner-only command) shows the current reply rate",
"delay": "Owner command. Usage: !delay [seconds1 [seconds2]]\nSet response delay in number of seconds. Without arguments it will list the current setting, 2 arguments will provide a range of seconds",
"reply2ignored": "Owner command. Usage: !reply2ignored [on|off]\nAllow/disallow replying to ignored users. Without arguments shows the current setting",
"stealth": "Owner command. Usage: !stealth [on|off]\nTurn stealth mode on or off (disable non-owner commands and don't return CTCP VERSION). Without arguments shows the current setting",
"quitmsg": "Owner command. Usage: !quitmsg [message]\nSet the quit message. Without arguments show the current quit message",
Expand Down Expand Up @@ -117,6 +118,7 @@ def __init__(self, my_pyborg, args):
"ignorelist": ("Ignore these nicknames:", []),
"reply2ignored": ("Reply to ignored people", 0),
"reply_chance": ("Chance of reply (%) per message", 33),
"delay": ("Response delay in seconds:", [0]),
"quitmsg": ("IRC quit message", "Bye :-("),
"password": ("password for control the bot (Edit manually !)", ""),
"autosaveperiod": ("Save every X minutes. Leave at 0 for no saving.", 60),
Expand Down Expand Up @@ -375,10 +377,15 @@ def on_msg(self, c, e):
if body[0] == "!":
if self.irc_commands(body, source, target, c, e) == 1:return

# Calculate delay
delay = self.settings.delay[0]
if len(self.settings.delay) == 2:
delay = random.randint(self.settings.delay[0], self.settings.delay[1])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For even more realism I'd suggest using

delay = random.uniform(self.settings.delay[0], self.settings.delay[1])

so that a random float is picked instead of just an integer amount of seconds.



# Pass message onto pyborg
if source in self.owners and e.source() in self.owner_mask:
self.pyborg.process_msg(self, body, replyrate, learn, (body, source, target, c, e), owner=1)
self.pyborg.process_msg(self, body, replyrate, learn, (body, source, target, c, e), owner=1, delay=delay)
else:
#start a new thread
thread.start_new_thread(self.pyborg.process_msg, (self, body, replyrate, learn, (body, source, target, c, e)))
Expand Down Expand Up @@ -556,6 +563,20 @@ def irc_commands(self, body, source, target, c, e):
for x in xrange (2, len (command_list)):
phrase = phrase + str(command_list[x]) + " "
self.output("\x01ACTION " + phrase + "\x01", ("", command_list[1], "", c, e))
elif command_list[0] == "!delay":
# if no arguments are given return the current delay
if len(command_list) == 1:
msg = "The current delay is "
for x in xrange(0, len(self.settings.delay)):
msg = msg + str(self.settings.delay[x]) + " "
# Set the new delay value(s)
# eg !delay 7 11
else:
delay_range = []
for x in xrange(1, len(command_list)):
delay_range.append(int(command_list[x]))
msg = "done"
self.settings.delay = delay_range
# Save changes
save_myname = self.settings.myname
if self.wanted_myname is not None:
Expand Down
5 changes: 4 additions & 1 deletion lib/pyborg/pyborg.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def save_all(self):
finally:
self.saving = False

def process_msg(self, io_module, body, replyrate, learn, args, owner = 0):
def process_msg(self, io_module, body, replyrate, learn, args, owner = 0, delay = 0):
"""
Process message 'body' and pass back to IO module with args.
If owner==1 allow owner commands.
Expand Down Expand Up @@ -332,6 +332,9 @@ def process_msg(self, io_module, body, replyrate, learn, args, owner = 0):
# Make a reply if desired
if random.randint(0, 99) < replyrate:

if delay > 0:
time.sleep(delay)

message = ""

#Look if we can find a prepared answer
Expand Down