Mostly code style changes

master
luk3yx 2019-06-20 18:21:25 +12:00
parent 12347cb1a6
commit adda651e0f
2 changed files with 15 additions and 13 deletions

View File

@ -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()

View File

@ -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()