krylon/plugins/krylon.py

84 lines
2.5 KiB
Python
Raw Normal View History

2021-03-06 13:45:47 +00:00
# -*- coding: utf-8 -*-
2021-03-06 20:37:38 +00:00
from irc3.plugins.command import command
2021-03-06 13:45:47 +00:00
import irc3
2021-03-06 21:58:55 +00:00
import os
2021-03-06 21:53:25 +00:00
import random
2021-03-06 13:45:47 +00:00
testfile = ['a'*40,'b'*40,'c'*40,'d'*40,'1'*40,'2'*40,'3'*40,'4'*40]
KRYLON_FILE = testfile
2021-03-06 23:47:32 +00:00
TOTAL_BOTS = 0
2021-03-06 13:45:47 +00:00
CONNECTED_BOTS = []
ONLINE_BOTS = []
INITIALIZED = 0
2021-03-06 21:53:25 +00:00
dir_path = os.path.dirname(os.path.realpath(__file__))
2021-03-06 13:45:47 +00:00
@irc3.plugin
class Plugin(object):
def __init__(self, context):
self.log = context.log
self.context = context
self.channel = context.config.channel
self.init = 0
2021-03-06 23:47:32 +00:00
self.total_bots = 0
2021-03-06 13:45:47 +00:00
2021-03-06 21:53:25 +00:00
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)))
2021-03-06 22:41:08 +00:00
return greet
2021-03-06 21:53:25 +00:00
2021-03-06 22:50:43 +00:00
def __symbol(self):
2021-03-06 21:53:25 +00:00
symbol_db = '%s/symbol.db' % dir_path
symbol = random.choice(list(open(symbol_db)))
2021-03-06 22:41:08 +00:00
return symbol
2021-03-06 21:53:25 +00:00
2021-03-06 13:45:47 +00:00
def krylon(self):
if self.init == 0:
KRYLON_FILE.reverse()
self.init = 1
2021-03-06 21:53:25 +00:00
NICK='d'
2021-03-06 22:41:08 +00:00
MSG='{}: <<<ARMED>>>'.format(NICK)
2021-03-06 13:45:47 +00:00
CHN='#sh0rtbus'
2021-03-06 21:53:25 +00:00
MSG = self.__emoj(MSG)
2021-03-06 13:45:47 +00:00
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)
2021-03-06 22:41:08 +00:00
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:
2021-03-06 23:12:23 +00:00
if BOT.config['botnet'][_].nick == BOT.nick:
2021-03-06 23:09:22 +00:00
BID= _
2021-03-06 22:41:08 +00:00
MSG='{}: {} {} < {}'.format(NICK,SYMBOL,GREET,BID)
CHN='#sh0rtbus'
MSG = self._Plugin__emoj(MSG)
2021-03-06 23:47:32 +00:00
BOT.privmsg(CHN,MSG)
if len(ONLINE_BOTS) == len(self.context.config.botnet):
2021-03-06 13:45:47 +00:00
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)