Example #1
0
def main():
    Log.info('Strat initializing....')
    Log.info('Debug enable: {}', Log.get_debug_info()[0])
    Log.debug(1, 'Debug level: {}', Log.get_debug_info()[1])
    bot_class()
    Log.info('Bot is now running!')
    if Config.git.switch:
        Log.info('Starting BackupSQL daemon')
        BackupSQL.sql_backup_daemon().start()
        Log.info('BackupSQL daemon is now running')
    while True:
        time.sleep(30)
Example #2
0
 def load(self):
     Log.debug(2, 'Entering group_cache_class.load()')
     self.__init__()
     with MainDatabase() as db:
         result = db.query("SELECT * FROM `welcomemsg`")
     for x in result:
         self.add(x)
     #if init:
     #syncLock.release()
     #kwargs['syncLock'].release()
     Log.info('Load welcomemsg table successful.')
     Log.debug(2, 'Exiting group_cache_class.load()')
Example #3
0
	def custom_init(self, *args, **kwargs):
		self.syncLock = Lock()
		self.cache = DiskCache('data/id_cache', default_return_type=dict())
		self.external_store = self.cache.read_without_except()
		with self.syncLock:
			t = Thread(target=self.__specfunc)
			t.daemon = True
			t.start()
			Log.info('Initializing other cache')
			self.gcache = group_cache_class(init=self)
			self.gcache.load()
		self.pcache = poem_class()
		self.fail_with_md = 'Markdown configure error, check settings or contact bot administrator if you think you are right'
Example #4
0
 def start(self, times):
     Log.info('Start random process')
     for time in xrange(0, times):
         Log.info('Current group:{}', repr(self.l))
         r = random.randint(50000, 99999)
         Log.info('Randomize list {} times', r)
         for x in xrange(0, r):
             self.rand_list()
         Log.info('Randomize done. Current group:{}', repr(self.l))
         result = self.l.pop(random.randint(0, len(self.l) - 1))
         self.winner.append(result)
         Log.info('Round {} Winner is : {} (id:{})', time + 1,
                  b64decode(self.member.pop(result)), result)
     self.cleanup()
Example #5
0
 def __init__(self, *args, **kwargs):
     Log.debug(2, 'Enter telepot_bot.__init__()')
     WAIT_TIME = 0.03
     Log.debug(2, '[bot_token = {}]', Config.bot.bot_token)
     Log.info('Initializing bot settings...')
     self.bot = TelepotBotBase.Bot(Config.bot.bot_token)
     self.bot_id = int(
         Config.bot.bot_token[:Config.bot.bot_token.find(':')])
     Log.info('Success login telegram bot with Token {}**************',
              Config.bot.bot_token[:Config.bot.bot_token.find(':') + 5])
     Log.info('Loading telepot_bot.custom_init()')
     self.fail_with_md = None
     self.custom_init(*args, **kwargs)
     Log.info('Loading telepot_bot.custom_init() successful')
     Log.info('Bot settings initialized successful!')
     Log.debug(2, 'Exit telepot_bot.__init__()')
Example #6
0
def backupThread():
    Log.info('Starting backup function')
    while True:
        now_time = time.strftime('%Y%m%d_%H%M%S')
        os.system("tar czfP {}/{}.tar.gz {}/world".format(
            Config.backup.webroot, now_time, Config.backup.mc_path))
        try:
            with open('{}/LATEST2'.format(Config.backup.webroot),
                      'w') as fout, open('{}/LATEST'.format(
                          Config.backup.webroot)) as fin:
                fout.write(fin.read())
        except IOError:
            pass
        with open('{}/LATEST'.format(Config.backup.webroot), 'w') as fout:
            fout.write(now_time)
        Log.info('{}.tar.gz backuped.', now_time)
        fileChecking(Config.backup.webroot)
        time.sleep(Config.backup.interval)
 def add(self, x, need_check_admin=True, not_found=False):
     if need_check_admin:
         try:
             result = {
                 True: 1,
                 False: 0
             }.get(
                 self.bot.getChatMember(x[0], self.bot.getid())['status'])
         except telepot.exception.BotWasKickedError:
             if not not_found:
                 self.__db_del(x[0])
                 Log.info('Delete kicked chat:{}', x[0])
                 return
         except telepot.exception.TelegramError as e:
             if e[0] == 'Bad Request: chat not found':
                 if not not_found:
                     self.__db_del(x[0])
                     Log.warn('Delete not found chat:{}', x[0])
                 Log.warn(
                     'in group_cache_class.add() chat_id : {} not found',
                     x[0])
             elif 'Forbidden: bot is not a member of the' in e[0]:
                 self.__db_del(x[0])
                 Log.warn('Delete kicked chat:{}', x[0])
             else:
                 raise e
         finally:
             result = 0
     else:
         result = 0
     self.g[x[0]] = {
         'msg': x[1],
         'is_admin': result,
         'poemable': x[2],
         'ignore_err': x[3],
         'noblue': x[4],
         'other': gc_base_switch(flag_name, x[5]),
         'except': eval(b64decode(x[6]))
     }
Example #8
0
def main():
    Log.info('Strat initializing....')
    Log.info('Debug enable: {}', Log.get_debug_info()[0])
    Log.debug(1, 'Debug level: {}', Log.get_debug_info()[1])
    bot_class()
    Log.info('Bot is now running!')
    while True:
        time.sleep(30)
Example #9
0
def mainRequest(LATEST):
    r = requests.get('{}/LATEST'.format(Config.backup.website), timeout=10)
    if LATEST == r.text:
        return LATEST
    _LATEST = LATEST
    LATEST = r.text
    s = requests.get('{}/{}.tar.gz'.format(Config.backup.website, LATEST),
                     stream=True,
                     timeout=10)
    try:
        s.raise_for_status()
    except Exception as e:
        Log.error('Catched Exception:`{}\'', repr(e))
        return _LATEST
    # From: https://stackoverflow.com/questions/16694907/how-to-download-large-file-in-python-with-requests-py
    with open("{}/{}.tar.gz".format(Config.backup.download_path, LATEST),
              'wb') as fout:
        for chunk in s.iter_content(chunk_size=1024):
            if not chunk: break
            fout.write(chunk)
    Log.info('{}.tar.gz downloaded.', LATEST)
    fileChecking(Config.backup.download_path)
    return LATEST
Example #10
0
 def cleanup(self):
     Log.info('Runing cleanup(), this function will print winner list.')
     memberpoolx = memberpool(usage_str='Member')
     aftermemberpool = memberpool(Config.bot.other_store,
                                  'New/Ignore member')
     for x in self.winner:
         Log.info('{} : {}', x, b64decode(memberpoolx.members[x]))
         memberpoolx.delete(x)
         aftermemberpool.write(x, 'null')
     Log.info('All clean up!')
Example #11
0
 def message_loop(self, on_message_function):
     Log.info('Starting message_loop()')
     self.bot.message_loop(on_message_function)
     Log.info('message_loop() is now started!')