Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
Cleaned up some duplicate code and added support for channel broadcast
Browse files Browse the repository at this point in the history
  • Loading branch information
iamtew committed Oct 12, 2014
1 parent 31607cc commit 6c850f8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ And you can specify multiple targets, like this:
echo "#chatroom,#otherchannel multi-chat" | ncat -4 localhost 5234
```

Broadcast to all channels the bot is configured to join by specifying `#*`:
```
echo "#* broadcast" | ncat -4 localhost 5234
22 changes: 10 additions & 12 deletions irccat.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def irccat_logger(bot, src, body, level=False):
Write messages to our log with timestamp and source IP.
Also write to debug log if we set a level
"""
message = str(datetime.now()) + ': From: ' + src + ':' + body
message = str(datetime.now()) + ': From: ' + src + ': ' + body
logfile = open(os.path.join(bot.config.logdir, 'irccat.log'), 'a')
logfile.write(message)
logfile.close()
Expand All @@ -44,19 +44,17 @@ def irccat_targets(bot, targets):
easily loop through them when sending messages.
"""
result = []
if ',' in targets:
for s in targets.split(','):
if re.search('^@', s):
result.append(re.sub('^@', '', s))

elif re.search('^#', s) and s in bot.config.core.channels:
result.append(s)
else:
if re.search('^@', targets):
result.append(re.sub('^@', '', targets))
for s in targets.split(','):
if re.search('^@', s):
result.append(re.sub('^@', '', s))

elif re.search('^#', s) and s in bot.config.core.channels:
result.append(s)

elif re.search('^#', targets):
result.append(targets)
elif re.search('^#\*$', s):
for c in bot.config.core.channels:
result.append(c)

return result

Expand Down

0 comments on commit 6c850f8

Please sign in to comment.