55 lines
2.0 KiB
Python
55 lines
2.0 KiB
Python
import re
|
|
import random
|
|
|
|
print("[ + ] Loaded bot.py")
|
|
|
|
class Bot():
|
|
def __init__(self, state):
|
|
print("[ + ] Bot() init ")
|
|
self.state = state
|
|
self.f = None
|
|
self.tbl = [
|
|
('^PING :(?P<token>.*)$', self.ping),
|
|
('^[^ ]+ INVITE [^ ]+ :(?P<channel>[^ ]+)$', self.invite),
|
|
('^:(?P<nick>.+)!(.+)@(.+) JOIN (?P<channel>.+)$', self.join),
|
|
('^:(?P<nick>.+)!(.+)@(.+) PRIVMSG [@]?(?P<channel>[^ ]+) :(?P<message>.*)$', self.privmsg),
|
|
]
|
|
|
|
def connect(self, config):
|
|
print("PASS %s" % (config.serverpass), file=self.f)
|
|
print("USER %s %s %s %s" % (config.username, config.username, config.username, config.username), file=self.f)
|
|
print("NICK %s" % (config.username), file=self.f)
|
|
print("PRIVMSG NickServ :Identify %s\n" % (config.password), file=self.f)
|
|
for channel in config.channels:
|
|
print("JOIN %s" % channel, file=self.f)
|
|
|
|
def ping(self, m):
|
|
token = m.group('token')
|
|
print("[PONG] %s" % token)
|
|
print(("PONG %s" % token), file=self.f)
|
|
|
|
def invite(self, m):
|
|
print(("JOIN %s" % m.group('channel')))
|
|
print(("JOIN %s" % m.group('channel')), file=self.f)
|
|
|
|
def join(self, m):
|
|
if m.group('channel') == '#SPARTA':
|
|
print('KICK %s %s :%s' % (m.group('channel'), m.group('nick'), "THIS! IS! SPARTA!"), file=self.f)
|
|
return
|
|
|
|
def privmsg(self, m):
|
|
if m.group('channel') == '#anon':
|
|
print('PRIVMSG %s :%s' % (m.group('channel'), m.group('message')), file=self.f)
|
|
return
|
|
|
|
if m.group('channel') == '#prize':
|
|
message = random.choice(['snake eyes.', '$100'])
|
|
print('PRIVMSG MemoServ :SEND %s %s' % (m.group('nick'), message), file=self.f)
|
|
return
|
|
|
|
# else
|
|
if 'ctr' not in self.state:
|
|
self.state['ctr'] = 0
|
|
print('PRIVMSG %s :%s' % (m.group('channel'), self.state['ctr']), file=self.f)
|
|
self.state['ctr'] += 1
|