Mostly code style changes
parent
12347cb1a6
commit
adda651e0f
21
example.py
21
example.py
|
@ -6,8 +6,8 @@
|
||||||
# © 2018 by luk3yx
|
# © 2018 by luk3yx
|
||||||
#
|
#
|
||||||
|
|
||||||
import sys
|
import miniirc, sys
|
||||||
from miniirc import IRC
|
assert miniirc.ver >= (1,4,0), 'This bot requires miniirc >= v1.4.0.'
|
||||||
|
|
||||||
# Variables
|
# Variables
|
||||||
nick = 'miniirc-test' + str(hash('.'))[1:4] # Make a unique(-ish) nickname
|
nick = 'miniirc-test' + str(hash('.'))[1:4] # Make a unique(-ish) nickname
|
||||||
|
@ -24,22 +24,22 @@ port = 6697
|
||||||
|
|
||||||
# Welcome!
|
# Welcome!
|
||||||
print('Welcome to {}!'.format(nick), file=sys.stderr)
|
print('Welcome to {}!'.format(nick), file=sys.stderr)
|
||||||
irc = IRC(ip, port, nick, channels, ident = ident, realname = realname,
|
irc = IRC(ip, port, nick, channels, ident=ident, realname=realname,
|
||||||
ns_identity = identity, debug = debug, auto_connect = False)
|
ns_identity=identity, debug=debug, auto_connect=False)
|
||||||
|
|
||||||
# Handle normal messages
|
# Handle normal messages
|
||||||
# This could probably be better than a large if/else statement.
|
# 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):
|
def handle_privmsg(irc, hostmask, args):
|
||||||
channel = args[0]
|
channel = args[0]
|
||||||
text = args[-1][1:].split(' ')
|
text = args[-1].split(' ')
|
||||||
cmd = text[0].lower()
|
cmd = text[0].lower()
|
||||||
# Unprefixed commands here
|
# Unprefixed commands here
|
||||||
if cmd.startswith("meep"):
|
if cmd.startswith('meep'):
|
||||||
irc.msg(channel, "Meep™!")
|
irc.msg(channel, '\u200bMeep!')
|
||||||
elif cmd.startswith(prefix):
|
elif cmd.startswith(prefix):
|
||||||
# Prefixed commands
|
# Prefixed commands
|
||||||
cmd = cmd[1:]
|
cmd = cmd[len(prefix):]
|
||||||
if cmd == 'yay':
|
if cmd == 'yay':
|
||||||
irc.msg(channel, '\u200bYay!')
|
irc.msg(channel, '\u200bYay!')
|
||||||
elif cmd == 'rev':
|
elif cmd == 'rev':
|
||||||
|
@ -54,4 +54,5 @@ def handle_privmsg(irc, hostmask, args):
|
||||||
'I am {}, an example miniirc bot.'.format(irc.nick))
|
'I am {}, an example miniirc bot.'.format(irc.nick))
|
||||||
|
|
||||||
# Connect
|
# Connect
|
||||||
irc.connect()
|
if __name__ == '__main__':
|
||||||
|
irc.connect()
|
||||||
|
|
|
@ -26,8 +26,8 @@ port = 6697
|
||||||
|
|
||||||
# Welcome!
|
# Welcome!
|
||||||
print("Welcome to stdinbot!", file=sys.stderr)
|
print("Welcome to stdinbot!", file=sys.stderr)
|
||||||
irc = IRC(ip, port, nick, channels, ident = ident, realname = realname,
|
irc = IRC(ip, port, nick, channels, ident=ident, realname=realname,
|
||||||
ns_identity = identity, debug = debug, auto_connect = False)
|
ns_identity=identity, debug=debug, auto_connect=False)
|
||||||
|
|
||||||
# Read stdin
|
# Read stdin
|
||||||
@irc.Handler('001')
|
@irc.Handler('001')
|
||||||
|
@ -43,4 +43,5 @@ def handle_stdin(irc, hostmask, args):
|
||||||
irc.msg(channels[0], line)
|
irc.msg(channels[0], line)
|
||||||
time.sleep(interval)
|
time.sleep(interval)
|
||||||
|
|
||||||
irc.connect()
|
if __name__ == '__main__':
|
||||||
|
irc.connect()
|
||||||
|
|
Loading…
Reference in New Issue