def __init__(self, bot): self.bot = bot self.commands = self.bot.trans.plugins.administration.commands self.description = self.bot.trans.plugins.administration.description self.administration = AutosaveDict('polaris/data/%s.administration.json' % self.bot.name) self.groups = AutosaveDict('polaris/data/%s.groups.json' % self.bot.name) self.users = AutosaveDict('polaris/data/%s.users.json' % self.bot.name)
def __init__(self, name): self.name = name self.config = AutosaveDict('bots/%s.json' % self.name) self.trans = AutosaveDict('polaris/translations/%s.json' % self.config.translation) self.bindings = importlib.import_module( 'polaris.bindings.%s' % self.config.bindings).bindings(self) self.inbox = Queue() self.outbox = Queue() self.started = False self.plugins = None self.info = None
def run(self, m): groups = AutosaveDict('polaris/data/%s.groups.json' % self.bot.name) users = AutosaveDict('polaris/data/%s.users.json' % self.bot.name) tag = subprocess.check_output(['git', 'describe', '--tags']).decode('ascii').rstrip('\n') greeting = self.bot.trans.plugins.about.strings.greeting % self.bot.info.first_name version = self.bot.trans.plugins.about.strings.version % (tag) # license = self.bot.trans.plugins.about.strings.license help = self.bot.trans.plugins.about.strings.help % self.bot.config.prefix stats = self.bot.trans.plugins.about.strings.stats % (len(users), len(groups)) text = '%s\n\n%s\n\n%s\n\n%s' % (greeting, help, version, stats) self.bot.send_message(m, text, extra={'format': 'HTML'})
def set_setting(bot, uid, key, value): settings = AutosaveDict('polaris/data/%s.settings.json' % bot.name) uid = str(uid) if not uid in settings: settings[uid] = {} settings[uid][key] = value settings.store_database()
def __init__(self, bot): self.bot = bot self.commands = self.bot.trans.plugins.reminders.commands self.description = self.bot.trans.plugins.reminders.description self.reminders = AutosaveDict('polaris/data/%s.reminders.json' % self.bot.name) self.sort_reminders()
def get_setting(bot, uid, key): settings = AutosaveDict('polaris/data/%s.settings.json' % bot.name) uid = str(uid) try: return settings[uid][key] except: return None
def del_setting(bot, uid, key): settings = AutosaveDict('polaris/data/%s.settings.json' % bot.name) if not isinstance(uid, str): uid = str(uid) del (settings[uid][key]) settings.store_database()
def set_step(bot, target, plugin, step): steps = AutosaveDict('polaris/data/%s.steps.json' % bot.name) if not isinstance(target, str): target = str(target) steps[target] = {'plugin': plugin, 'step': step} steps.store_database()
def set_tag(bot, target, tag): tags = AutosaveDict('polaris/data/%s.tags.json' % bot.name) if not target in tags: tags[target] = [] if not tag in tags[target]: tags[target].append(tag) tags.store_database()
def del_tag(bot, target, tag): tags = AutosaveDict('polaris/data/%s.tags.json' % bot.name) if not isinstance(target, str): target = str(target) tags[target].remove(tag) tags.store_database()
def cancel_steps(bot, target): steps = AutosaveDict('polaris/data/%s.steps.json' % bot.name) if not isinstance(target, str): target = str(target) if target in steps: del steps[target] steps.store_database()
def get_step(bot, target): steps = AutosaveDict('polaris/data/%s.steps.json' % bot.name) if not isinstance(target, str): target = str(target) if not target in steps: return None else: return steps[target]
def has_tag(bot, target, tag, return_match=False): tags = AutosaveDict('polaris/data/%s.tags.json' % bot.name) if not isinstance(target, str): target = str(target) if target in tags and '?' in tag: for target_tag in tags[target]: if target_tag.startswith(tag.split('?')[0]): if return_match: return target_tag else: return True return False elif target in tags and tag in tags[target]: return True else: return False
def __init__(self, bot): self.bot = bot self.commands = self.bot.trans.plugins.pins.commands self.description = self.bot.trans.plugins.pins.description self.pins = AutosaveDict('polaris/data/%s.pins.json' % self.bot.name) self.update_triggers()
def has_tag(bot, target, tag): tags = AutosaveDict('polaris/data/%s.tags.json' % bot.name) if target in tags and tag in tags[target]: return True else: return False
def bot_config(name): config = AutosaveDict('bots/%s.json' % name) i = 1 finished = False while not finished: text = 'Editing /bots/%s.json\n' % name if 'bindings' in config: bindings = config['bindings'] else: bindings = 'telegram-bot-api' if 'bindings_token' in config: bindings_token = config['bindings_token'] else: bindings_token = 'YOUR TELEGRAM BOT TOKEN' if 'command_start' in config: command_start = config['command_start'] else: command_start = '/' if 'owner' in config: owner = config['owner'] else: owner = 0 if 'debug' in config: debug = config['debug'] else: debug = False if 'language' in config: language = config['language'] else: language = 'default' if 'plugins' in config: plugins = config['plugins'] else: plugins = load_plugin_list() if 'api_keys' in config: api_keys = config['api_keys'] else: api_keys = {} text += '(0) Finish editing\n' text += '(1) bindings: %s\n' % bindings text += '(2) bindings_token: %s\n' % bindings_token text += '(3) command_start: %s\n' % command_start text += '(4) owner: %s\n' % owner text += '(5) debug: %s\n' % debug text += '(6) language: %s\n' % language text += '(7) plugins: %s\n' % plugins text += '(8) api_keys: %s\n' % api_keys option = int(input(text)) if option == 0: print('Saving all values to "bots/%s.json".' % name) config.bindings = bindings config.bindings_token = bindings_token config.command_start = command_start config.owner = owner config.debug = debug config.language = language config.plugins = plugins config.api_keys = api_keys finished = True elif option == 1: option = input( 'What bindings want to use? (Current value: "%s")\n' % bindings) config.bindings = option
def del_tag(bot, target, tag): tags = AutosaveDict('polaris/data/%s.tags.json' % bot.name) tags[target].remove(tag) tags.store_database()