2018-09-13 20:47:16 -07:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
#
|
|
|
|
# Example miniirc-based bot
|
|
|
|
#
|
|
|
|
# © 2018 by luk3yx
|
|
|
|
#
|
|
|
|
|
2019-06-19 23:21:25 -07:00
|
|
|
import miniirc, sys
|
|
|
|
assert miniirc.ver >= (1,4,0), 'This bot requires miniirc >= v1.4.0.'
|
2018-09-13 20:47:16 -07:00
|
|
|
|
|
|
|
# Variables
|
|
|
|
nick = 'miniirc-test' + str(hash('.'))[1:4] # Make a unique(-ish) nickname
|
|
|
|
ident = nick
|
|
|
|
realname = 'Example miniirc bot - https://gitlab.com/luk3yx/stdinbot'
|
|
|
|
identity = None
|
|
|
|
# identity = '<username> <password>'
|
|
|
|
debug = False
|
|
|
|
channels = ['#lurk']
|
|
|
|
prefix = '`'
|
|
|
|
|
|
|
|
ip = 'xeroxirc.net'
|
|
|
|
port = 6697
|
|
|
|
|
|
|
|
# Welcome!
|
|
|
|
print('Welcome to {}!'.format(nick), file=sys.stderr)
|
2019-06-19 23:21:25 -07:00
|
|
|
irc = IRC(ip, port, nick, channels, ident=ident, realname=realname,
|
|
|
|
ns_identity=identity, debug=debug, auto_connect=False)
|
2018-09-13 20:47:16 -07:00
|
|
|
|
|
|
|
# Handle normal messages
|
|
|
|
# This could probably be better than a large if/else statement.
|
2019-06-19 23:21:25 -07:00
|
|
|
@irc.Handler('PRIVMSG', colon=False)
|
2018-09-13 20:47:16 -07:00
|
|
|
def handle_privmsg(irc, hostmask, args):
|
|
|
|
channel = args[0]
|
2019-06-19 23:21:25 -07:00
|
|
|
text = args[-1].split(' ')
|
2018-10-28 11:14:11 -07:00
|
|
|
cmd = text[0].lower()
|
2018-09-13 20:47:16 -07:00
|
|
|
# Unprefixed commands here
|
2019-06-19 23:21:25 -07:00
|
|
|
if cmd.startswith('meep'):
|
|
|
|
irc.msg(channel, '\u200bMeep!')
|
2018-09-13 20:47:16 -07:00
|
|
|
elif cmd.startswith(prefix):
|
|
|
|
# Prefixed commands
|
2019-06-19 23:21:25 -07:00
|
|
|
cmd = cmd[len(prefix):]
|
2018-09-13 20:47:16 -07:00
|
|
|
if cmd == 'yay':
|
2018-10-28 11:14:11 -07:00
|
|
|
irc.msg(channel, '\u200bYay!')
|
2018-09-13 20:47:16 -07:00
|
|
|
elif cmd == 'rev':
|
2018-10-28 11:14:11 -07:00
|
|
|
if len(text) > 1:
|
|
|
|
irc.msg(channel, "{}: {}".format(hostmask[0],
|
|
|
|
' '.join(text[1:])[::-1]))
|
2018-09-13 20:47:16 -07:00
|
|
|
else:
|
2018-10-28 11:14:11 -07:00
|
|
|
irc.msg(channel, 'Invalid syntax! Syntax: ' + prefix +
|
|
|
|
'rev <string>')
|
2018-09-13 20:47:16 -07:00
|
|
|
elif cmd == 'about':
|
2018-10-28 11:14:11 -07:00
|
|
|
irc.msg(channel,
|
|
|
|
'I am {}, an example miniirc bot.'.format(irc.nick))
|
2018-09-13 20:47:16 -07:00
|
|
|
|
|
|
|
# Connect
|
2019-06-19 23:21:25 -07:00
|
|
|
if __name__ == '__main__':
|
|
|
|
irc.connect()
|