krylon/plugins/krylon.py
2021-03-06 17:47:32 -06:00

84 lines
2.5 KiB
Python

# -*- coding: utf-8 -*-
from irc3.plugins.command import command
import irc3
import os
import random
testfile = ['a'*40,'b'*40,'c'*40,'d'*40,'1'*40,'2'*40,'3'*40,'4'*40]
KRYLON_FILE = testfile
TOTAL_BOTS = 0
CONNECTED_BOTS = []
ONLINE_BOTS = []
INITIALIZED = 0
dir_path = os.path.dirname(os.path.realpath(__file__))
@irc3.plugin
class Plugin(object):
def __init__(self, context):
self.log = context.log
self.context = context
self.channel = context.config.channel
self.init = 0
self.total_bots = 0
def __emoj(self,s):
emote_db = '%s/emote.db' % dir_path
emoj = random.choice(list(open(emote_db)))
random.randint(0,1)
if random.randint(0,1) == 0:
emoj = "\x0304{}\x0F".format(emoj)
else:
emoj = "\x0303{}\x0F".format(emoj)
s = s + '' + emoj
return s
def __greet(self):
greet_db = '%s/greet.db' % dir_path
greet = random.choice(list(open(greet_db)))
return greet
def __symbol(self):
symbol_db = '%s/symbol.db' % dir_path
symbol = random.choice(list(open(symbol_db)))
return symbol
def krylon(self):
if self.init == 0:
KRYLON_FILE.reverse()
self.init = 1
NICK='d'
MSG='{}: <<<ARMED>>>'.format(NICK)
CHN='#sh0rtbus'
MSG = self.__emoj(MSG)
self.context.privmsg(CHN,MSG)
@irc3.event(irc3.rfc.JOIN)
def welcome(self, mask, channel, **kw):
if mask.nick == self.context.nick:
ONLINE_BOTS.append(self.context.nick)
NICK='d'
SYMBOL=self._Plugin__symbol()
GREET=self._Plugin__greet()
BID='BOT'
BOT=self.context
bots='___'.join(BOT.config['botnet']).strip().split('___')
for _ in bots:
if BOT.config['botnet'][_].nick == BOT.nick:
BID= _
MSG='{}: {} {} < {}'.format(NICK,SYMBOL,GREET,BID)
CHN='#sh0rtbus'
MSG = self._Plugin__emoj(MSG)
BOT.privmsg(CHN,MSG)
if len(ONLINE_BOTS) == len(self.context.config.botnet):
self.krylon()
@irc3.event(irc3.rfc.CONNECTED)
def connected(self, **kw):
for _ in [x for x in self.context.config.botnet]:
if kw['me'] in self.context.config.botnet[_].nick:
CONNECTED_BOTS.append((_,kw['me']))
self.context.join(self.channel)