-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.py
executable file
·58 lines (51 loc) · 1.62 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/python3
#
# Example miniirc-based bot
#
# © 2018 by luk3yx
#
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
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)
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', colon=False)
def handle_privmsg(irc, hostmask, args):
channel = args[0]
text = args[-1].split(' ')
cmd = text[0].lower()
# Unprefixed commands here
if cmd.startswith('meep'):
irc.msg(channel, '\u200bMeep!')
elif cmd.startswith(prefix):
# Prefixed commands
cmd = cmd[len(prefix):]
if cmd == 'yay':
irc.msg(channel, '\u200bYay!')
elif cmd == 'rev':
if len(text) > 1:
irc.msg(channel, "{}: {}".format(hostmask[0],
' '.join(text[1:])[::-1]))
else:
irc.msg(channel, 'Invalid syntax! Syntax: ' + prefix +
'rev <string>')
elif cmd == 'about':
irc.msg(channel,
'I am {}, an example miniirc bot.'.format(irc.nick))
# Connect
if __name__ == '__main__':
irc.connect()