From adda651e0f4a05bab56254e8e020278e35d911d1 Mon Sep 17 00:00:00 2001 From: luk3yx Date: Thu, 20 Jun 2019 18:21:25 +1200 Subject: [PATCH] Mostly code style changes --- example.py | 21 +++++++++++---------- stdinbot.py | 7 ++++--- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/example.py b/example.py index 963487d..b64a96f 100755 --- a/example.py +++ b/example.py @@ -6,8 +6,8 @@ # © 2018 by luk3yx # -import sys -from miniirc import IRC +import miniirc, sys +assert miniirc.ver >= (1,4,0), 'This bot requires miniirc >= v1.4.0.' # Variables nick = 'miniirc-test' + str(hash('.'))[1:4] # Make a unique(-ish) nickname @@ -24,22 +24,22 @@ port = 6697 # Welcome! print('Welcome to {}!'.format(nick), file=sys.stderr) -irc = IRC(ip, port, nick, channels, ident = ident, realname = realname, - ns_identity = identity, debug = debug, auto_connect = False) +irc = IRC(ip, port, nick, channels, ident=ident, realname=realname, + ns_identity=identity, debug=debug, auto_connect=False) # Handle normal messages # This could probably be better than a large if/else statement. -@irc.Handler('PRIVMSG') +@irc.Handler('PRIVMSG', colon=False) def handle_privmsg(irc, hostmask, args): channel = args[0] - text = args[-1][1:].split(' ') + text = args[-1].split(' ') cmd = text[0].lower() # Unprefixed commands here - if cmd.startswith("meep"): - irc.msg(channel, "Meep™!") + if cmd.startswith('meep'): + irc.msg(channel, '\u200bMeep!') elif cmd.startswith(prefix): # Prefixed commands - cmd = cmd[1:] + cmd = cmd[len(prefix):] if cmd == 'yay': irc.msg(channel, '\u200bYay!') elif cmd == 'rev': @@ -54,4 +54,5 @@ def handle_privmsg(irc, hostmask, args): 'I am {}, an example miniirc bot.'.format(irc.nick)) # Connect -irc.connect() +if __name__ == '__main__': + irc.connect() diff --git a/stdinbot.py b/stdinbot.py index 3d5bc5b..d95fedc 100755 --- a/stdinbot.py +++ b/stdinbot.py @@ -26,8 +26,8 @@ port = 6697 # Welcome! print("Welcome to stdinbot!", file=sys.stderr) -irc = IRC(ip, port, nick, channels, ident = ident, realname = realname, - ns_identity = identity, debug = debug, auto_connect = False) +irc = IRC(ip, port, nick, channels, ident=ident, realname=realname, + ns_identity=identity, debug=debug, auto_connect=False) # Read stdin @irc.Handler('001') @@ -43,4 +43,5 @@ def handle_stdin(irc, hostmask, args): irc.msg(channels[0], line) time.sleep(interval) -irc.connect() +if __name__ == '__main__': + irc.connect()