-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbagre.py
86 lines (71 loc) · 2.64 KB
/
bagre.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import argparse
import logging
import irc.strings
import ib3
import ib3.auth
import ib3.connection
import ib3.nick
import os
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s %(name)s %(levelname)s: %(message)s',
datefmt='%Y-%m-%dT%H:%M:%SZ'
)
logging.captureWarnings(True)
logger = logging.getLogger('saslbot')
nick = os.environ['NICK']
passwd = os.environ['PASSWD']
channel = os.environ['CHANNEL']
class Bagre(ib3.auth.SASL, ib3.nick.Regain, ib3.connection.SSL, ib3.Bot):
def on_privmsg(self, conn, event):
self.do_command(conn, event, event.arguments[0])
def on_pubmsg(self, conn, event):
args = event.arguments[0].split(':', 1)
if len(args) > 1:
to = irc.strings.lower(args[0])
if to == irc.strings.lower(conn.get_nickname()):
self.do_command(conn, event, args[1].strip())
toNick = event.target
if toNick == conn.get_nickname():
toNick = event.source.nick
if 'windows' in args[0] or 'Windows' in args[0]:
conn.privmsg(toNick, 'mesmo pagando é uma bosta')
if '!help' in args[0]:
conn.privmsg(toNick, 'Ainda não tenho um help ou ajuda para mostrar, mas tente usar {}: !fortune'.format(nick))
conn.privmsg(to, 'Ajuda ae com novas funções: https://github.com/OpenBSD-BR/bagre')
def do_command(self, conn, event, cmd):
to = event.target
if to == conn.get_nickname():
to = event.source.nick
if cmd == 'disconnect':
self.disconnect()
elif cmd == 'die':
if to == 'shazaum':
self.die()
else:
conn.privmsg(to, 'Nah! vou ficar por aqui mesmo')
elif cmd == '!help':
conn.privmsg(to, 'Ainda não tenho um help ou ajuda para mostrar, mas tente usar {}: !fortune'.format(nick))
conn.privmsg(to, 'Ajuda ae com novas funções: https://github.com/OpenBSD-BR/bagre')
elif cmd == '!fortune':
txt = os.popen('fortune fortune-br').read()
for txt in txt.split('\n'):
conn.privmsg(to, txt)
else:
conn.privmsg(to, 'What does "{}" mean?'.format(cmd))
if __name__ == '__main__':
bot = Bagre(
server_list=[('irc.libera.chat', 6697)],
nickname=nick,
realname=nick,
ident_password=passwd,
channels=[channel],
)
try:
bot.start()
except KeyboardInterrupt:
bot.disconnect('KeyboardInterrupt!')
except Exception:
logger.exception('Killed by unhandled exception')
bot.disconnect('Exception!')
raise SystemExit()