def run(self, m): input = get_input(m) if not is_trusted(self.bot, m.sender.id): return self.bot.send_message( m, self.bot.trans.errors.permission_required, extra={'format': 'HTML'}) if not input: return self.bot.send_message( m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) if m.reply: target = str(m.reply.sender.id) name = m.reply.sender.first_name elif first_word(input) == '-g': target = str(m.conversation.id) name = m.conversation.title input = all_but_first_word(input) elif first_word(input).isdigit(): target = first_word(input) name = target input = all_but_first_word(input) else: target = str(m.sender.id) name = m.sender.first_name tags = input.split() # Adds a tag to user or group. # if is_command(self, 1, m.content): for tag in tags: if not has_tag(self.bot, target, tag): set_tag(self.bot, target, tag) return self.bot.send_message( m, self.bot.trans.plugins.tags.strings.tagged % (name, tags), extra={'format': 'HTML'}) # Removes a tag from user or group. # elif is_command(self, 2, m.content): for tag in tags: if has_tag(self.bot, target, tag): del_tag(self.bot, target, tag) return self.bot.send_message( m, self.bot.trans.plugins.tags.strings.untagged % (name, tags), extra={'format': 'HTML'})
def run(self, m): input = get_input(m, ignore_reply=False) if not input: return self.bot.send_message(m, generate_command_help( self, m.content), extra={'format': 'HTML'}) # return self.bot.send_message(m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) langs = [ 'af', 'aq', 'ar', 'hy', 'ca', 'zh', 'zh-cn', 'zh-tw', 'zh-yue', 'hr', 'cs', 'da', 'nl', 'en-au', 'en-uk', 'en-us', 'eo', 'fi', 'fr', 'de', 'el', 'ht', 'hu', 'is', 'id', 'it', 'ja', 'ko', 'la', 'lv', 'mk', 'no', 'pl', 'pt', 'pt-br', 'ro', 'ru', 'sr', 'sk', 'es', 'es-es', 'es-us', 'sw', 'sv', 'ta', 'th', 'tr', 'vi', 'cy' ] for lang in langs: if first_word(input) == lang: language = lang text = all_but_first_word(input) break else: if self.bot.config.translation != 'default': language = 'es-es' else: language = 'en-us' text = input if not text: return self.bot.send_message( m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) url = 'http://translate.google.com/translate_tts' params = { 'tl': language, 'q': text, 'ie': 'UTF-8', 'total': len(text), 'idx': 0, 'client': 'tw-ob', 'key': self.bot.config.api_keys.google_developer_console } headers = { "Referer": 'http://translate.google.com/', "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.8 Safari/537.36" } file = download(url, params, headers) voice = mp3_to_ogg(file) if voice: return self.bot.send_message(m, voice, 'voice') else: return self.bot.send_message(m, self.bot.trans.errors.download_failed)
def run(self, m): if not is_trusted(self.bot, m.sender.id): return self.bot.send_message(m, self.bot.trans.errors.permission_required, extra={'format': 'HTML'}) if not input: return self.bot.send_message(m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) input = get_input(m) if m.reply: target = str(m.reply.sender.id) name = m.reply.sender.first_name elif first_word(input) == '-g': target = str(m.conversation.id) name = m.conversation.title input = all_but_first_word(input) elif first_word(input).isdigit(): target = first_word(input) name = target input = all_but_first_word(input) else: target = str(m.sender.id) name = m.sender.first_name tags = input.split() # Adds a tag to user or group. # if is_command(self, 1, m.content): for tag in tags: if not has_tag(self.bot, target, tag): set_tag(self.bot, target, tag) return self.bot.send_message(m, self.bot.trans.plugins.tags.strings.tagged % (name, tags), extra={'format': 'HTML'}) # Removes a tag from user or group. # elif is_command(self, 2, m.content): for tag in tags: if has_tag(self.bot, target, tag): del_tag(self.bot, target, tag) return self.bot.send_message(m, self.bot.trans.plugins.tags.strings.untagged % (name, tags), extra={'format': 'HTML'})
def run(self, m): input = get_input(m, ignore_reply=False) if not input: return self.bot.send_message(m, generate_command_help( self, m.content), extra={'format': 'HTML'}) # return self.bot.send_message(m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) delay = first_word(input) if delay: delaytime = delay[:-1] unit = delay[-1:] if not is_int(delaytime) or is_int(unit) or not self.to_seconds( delaytime, unit): return self.bot.send_message( m, self.bot.trans.plugins.reminders.strings.wrongdelay) alarm = time() + self.to_seconds(delaytime, unit) text = all_but_first_word(input) if not text: return self.bot.send_message( m, self.bot.trans.plugins.reminders.strings.noreminder) reminder = DictObject(OrderedDict()) reminder.id = '%s:%s' % (m.sender.id, time()) reminder.alarm = alarm reminder.chat_id = m.conversation.id reminder.text = text reminder.first_name = m.sender.first_name if m.sender.username: reminder.username = m.sender.username self.bot.reminders = wait_until_received('reminders/' + self.bot.name) self.sort_reminders() self.bot.reminders['list'].append(reminder) self.sort_reminders() if unit == 's': delay = delay.replace('s', ' seconds') if unit == 'm': delay = delay.replace('m', ' minutes') if unit == 'h': delay = delay.replace('h', ' hours') if unit == 'd': delay = delay.replace('d', ' days') message = self.bot.trans.plugins.reminders.strings.added % ( m.sender.first_name, delay, text) return self.bot.send_message(m, message, extra={'format': 'HTML'})
def run(self, m): input = get_input(m, ignore_reply=False) if not input: return self.bot.send_message( m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) self.reminders.load_database() # Lists all pins # delay = first_word(input) if delay: delaytime = delay[:-1] unit = delay[-1:] if not is_int(delaytime) or is_int(unit): return self.bot.send_message( m, self.bot.trans.plugins.reminders.strings.wrongdelay) alarm = time() + self.to_seconds(delaytime, unit) text = all_but_first_word(input) if not text: return self.bot.send_message( m, self.bot.trans.plugins.reminders.strings.noreminder) reminder = DictObject(OrderedDict()) reminder.id = '%s:%s' % (m.sender.id, time()) reminder.alarm = alarm reminder.chat_id = m.conversation.id reminder.text = text reminder.first_name = m.sender.first_name reminder.username = m.sender.username self.reminders.list.append(reminder) self.sort_reminders() self.reminders.store_database() if unit == 's': delay = delay.replace('s', ' segundos') if unit == 'm': delay = delay.replace('m', ' minutos') if unit == 'h': delay = delay.replace('h', ' horas') if unit == 'd': delay = delay.replace('d', ' días') message = self.bot.trans.plugins.reminders.strings.added % ( m.sender.first_name, delay, text) return self.bot.send_message(m, message, extra={'format': 'HTML'})
def run(self, m): input = get_input(m, ignore_reply=False) if not input: return self.bot.send_message(m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) langs = [ 'af', 'aq', 'ar', 'hy', 'ca', 'zh', 'zh-cn', 'zh-tw', 'zh-yue', 'hr', 'cs', 'da', 'nl', 'en-au', 'en-uk', 'en-us', 'eo', 'fi', 'fr', 'de', 'el', 'ht', 'hu', 'is', 'id', 'it', 'ja', 'ko', 'la', 'lv', 'mk', 'no', 'pl', 'pt', 'pt-br', 'ro', 'ru', 'sr', 'sk', 'es', 'es-es', 'es-us', 'sw', 'sv', 'ta', 'th', 'tr', 'vi', 'cy' ] for lang in langs: if first_word(input) == lang: language = lang text = all_but_first_word(input) break else: language = 'en-us' text = input if not text: return self.bot.send_message(m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) url = 'http://translate.google.com/translate_tts' params = { 'tl': language, 'q': text, 'ie': 'UTF-8', 'total': len(text), 'idx': 0, 'client': 'tw-ob', 'key': self.bot.config.api_keys.google_developer_console } headers = { "Referer": 'http://translate.google.com/', "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.8 Safari/537.36" } file = download(url, params, headers) voice = mp3_to_ogg(file) if voice: return self.bot.send_message(m, voice, 'voice') else: return self.bot.send_message(m, self.bot.trans.errors.download_failed)
def run(self, m): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) input = get_input(m, ignore_reply=False) parameter = first_word(input) enabled = ['reactions', 'roulette', 'replies', 'pole', 'fiesta', 'nsfw'] disabled = ['antispam', 'antiarab', 'antirussian', 'polereset'] config = {} for param in enabled: config[param] = not has_tag( self.bot, m.conversation.id, 'no' + param) for param in disabled: config[param] = has_tag(self.bot, m.conversation.id, param) text = '' if not input: text = self.bot.trans.plugins.config.strings.explanation % "', '".join( config) for param in config: text += '\n' + ('✔️' if config[param] else '❌') + \ ' ' + self.bot.trans.plugins.config.strings[param] elif parameter in enabled or parameter in disabled: if not is_admin(self.bot, m.sender.id, m) and not is_trusted(self.bot, m.sender.id, m): return self.bot.send_message(m, self.bot.trans.errors.permission_required, extra={'format': 'HTML'}) if config[parameter]: if parameter in enabled: set_tag(self.bot, m.conversation.id, 'no' + parameter) elif parameter in disabled: del_tag(self.bot, m.conversation.id, parameter) else: if parameter in enabled: del_tag(self.bot, m.conversation.id, 'no' + parameter) elif parameter in disabled: set_tag(self.bot, m.conversation.id, parameter) text = ('❌' if config[parameter] else '✔️') + \ ' ' + self.bot.trans.plugins.config.strings[parameter] return self.bot.send_message(m, text, extra={'format': 'HTML'})
def run(self, m): input = get_input(m, ignore_reply=False) if not input: return self.bot.send_message(m, self.bot.trans.errors.missing_parameter, extra={"format": "HTML"}) self.reminders.load_database() # Lists all pins # delay = first_word(input) if delay: delaytime = delay[:-1] unit = delay[-1:] if not is_int(delaytime) or is_int(unit): return self.bot.send_message(m, self.bot.trans.plugins.reminders.strings.wrongdelay) alarm = time() + self.to_seconds(delaytime, unit) text = all_but_first_word(input) if not text: return self.bot.send_message(m, self.bot.trans.plugins.reminders.strings.noreminder) reminder = DictObject(OrderedDict()) reminder.id = "%s:%s" % (m.sender.id, time()) reminder.alarm = alarm reminder.chat_id = m.conversation.id reminder.text = text reminder.first_name = m.sender.first_name reminder.username = m.sender.username self.reminders.list.append(reminder) self.sort_reminders() self.reminders.store_database() if unit == "s": delay = delay.replace("s", " seconds") if unit == "m": delay = delay.replace("m", " minutes") if unit == "h": delay = delay.replace("h", " hours") if unit == "d": delay = delay.replace("d", " days") message = self.bot.trans.plugins.reminders.strings.added % (m.sender.first_name, delay, text) return self.bot.send_message(m, message, extra={"format": "HTML"})
def run(self, m): input = get_input(m) if not is_owner(self.bot, m.sender.id) and not is_trusted(self.bot, m.sender.id): return self.bot.send_message(m, self.bot.trans.errors.permission_required, extra={'format': 'HTML'}) if not input: return self.bot.send_message(m, generate_command_help(self, m.content), extra={'format': 'HTML'}) # return self.bot.send_message(m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) if not m.reply: input = all_but_first_word(input) target = get_target(self.bot, m, get_input(m)) if target: name = get_username(self.bot, target, False) elif first_word(input) == '-g': target = str(m.conversation.id) name = get_username(self.bot, target, False) else: target = str(m.sender.id) name = get_username(self.bot, target, False) tags = input.split() if not target: return self.bot.send_message(m, self.bot.trans.errors.no_results, extra={'format': 'HTML'}) # Adds a tag to user or group. # if is_command(self, 1, m.content): for tag in tags: if not has_tag(self.bot, target, tag): set_tag(self.bot, target, tag) return self.bot.send_message(m, self.bot.trans.plugins.tags.strings.tagged % (name, tags), extra={'format': 'HTML'}) # Removes a tag from user or group. # elif is_command(self, 2, m.content): for tag in tags: if has_tag(self.bot, target, tag): del_tag(self.bot, target, tag) return self.bot.send_message(m, self.bot.trans.plugins.tags.strings.untagged % (name, tags), extra={'format': 'HTML'})
def run(self, m): input = get_input(m) uid = str(m.sender.id) gid = str(m.conversation.id) # List all administration commands. # if is_command(self, 1, m.content): text = self.bot.trans.plugins.administration.strings.commands for command in self.commands: # Adds the command and parameters# if self.commands[-1]['command'].replace('/', self.bot.config.prefix) in m.content: text += '\n' + command['command'].lstrip('/') if 'description' in command: text += ' - %s' % command['description'] else: text += ' - ?¿' else: text += '\n • ' + command['command'].replace('/', self.bot.config.prefix) if 'parameters' in command: for parameter in command['parameters']: name, required = list(parameter.items())[0] # Bold for required parameters, and italic for optional # if required: text += ' <b><%s></b>' % name else: text += ' [%s]' % name if 'description' in command: text += '\n <i>%s</i>' % command['description'] else: text += '\n <i>?¿</i>' text += '\n <i>?¿</i>' return self.bot.send_message(m, text, extra={'format': 'HTML'}) # List all groups. # if is_command(self, 2, m.content): text = self.bot.trans.plugins.administration.strings.groups for gid, attr in self.administration.items(): text += '\n • %s |%s|' % (self.groups[gid]['title'], attr['alias']) return self.bot.send_message(m, text, extra={'format': 'HTML'}) # Join a group. # elif is_command(self, 3, m.content): if not input: return self.bot.send_message(m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) for id in self.administration: if (input in self.administration or input in self.administration[id]['alias'] or input in self.groups[id]['title']): gid_to_join = id break if not gid_to_join in self.administration: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) text = '<b>%s</b>\n<i>%s</i>\n\n%s' % (self.groups[gid_to_join]['title'], self.administration[gid_to_join]['description'], self.bot.trans.plugins.administration.strings.rules) i = 1 for rule in self.administration[gid_to_join]['rules']: text += '\n %s. <i>%s</i>' % (i, rule) i += 1 if not self.administration[gid_to_join]['rules']: text += '\n%s' % self.bot.trans.plugins.administration.strings.norules if not self.administration[gid_to_join]['link']: text += '\n\n%s' % self.bot.trans.plugins.administration.strings.nolink else: text += '\n\n<a href="%s">%s</a>' % (self.administration[gid_to_join]['link'], self.bot.trans.plugins.administration.strings.join) return self.bot.send_message(m, text, extra={'format': 'HTML', 'preview': False}) # Information about a group. # elif is_command(self, 4, m.content) or is_command(self, 9, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not gid in self.administration: if is_command(self, 4, m.content): return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) elif is_command(self, 9, m.content): return text = '<b>%s</b>\n<i>%s</i>\n\n%s' % (self.groups[gid]['title'], self.administration[gid]['description'], self.bot.trans.plugins.administration.strings.rules) i = 1 for rule in self.administration[gid]['rules']: text += '\n %s. <i>%s</i>' % (i, rule) i += 1 if not self.administration[gid]['rules']: text += '\n%s' % self.bot.trans.plugins.administration.strings.norules if is_command(self, 4, m.content): if not self.administration[gid]['link']: text += '\n\n%s' % self.bot.trans.plugins.administration.strings.nolink else: text += '\n\n<a href="%s">%s</a>' % (self.bot.trans.plugins.administration.strings.join. self.administration[gid]['link']) return self.bot.send_message(m, text, extra={'format': 'HTML', 'preview': False}) # Rules of a group. # elif is_command(self, 5, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not gid in self.administration: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) if input and is_int(input): try: i = int(input) text = '%s. <i>%s</i>' % (i, self.administration[gid]['rules'][i - 1]) except: text = self.bot.trans.plugins.administration.strings.notfound else: text = self.bot.trans.plugins.administration.strings.rules i = 1 for rule in self.administration[gid]['rules']: text += '\n %s. <i>%s</i>' % (i, rule) i += 1 if not self.administration[gid]['rules']: text += '\n%s' % self.bot.trans.plugins.administration.strings.norules return self.bot.send_message(m, text, extra={'format': 'HTML', 'preview': False}) # Kicks a user. # elif is_command(self, 6, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not is_mod(self.bot, m.sender.id, m.conversation.id): return self.bot.send_message(m, self.bot.trans.errors.permission_required, extra={'format': 'HTML'}) if not input and not m.reply: return self.bot.send_message(m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) if m.reply: target = m.reply.sender.id elif input: target = input else: target = m.sender.id res = self.bot.kick_user(m, target) self.bot.unban_user(m, target) if res is None: return self.bot.send_message(m, self.bot.trans.errors.admin_required, extra={'format': 'HTML'}) elif not res: return self.bot.send_message(m, self.bot.trans.errors.failed, extra={'format': 'HTML'}) else: return self.bot.send_message(m, '<pre>An enemy has been slain.</pre>', extra={'format': 'HTML'}) return self.bot.send_message(m, self.bot.trans.errors.unknown, extra={'format': 'HTML'}) # Bans a user. # elif is_command(self, 7, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not is_mod(self.bot, m.sender.id, m.conversation.id): return self.bot.send_message(m, self.bot.trans.errors.permission_required, extra={'format': 'HTML'}) if not input: return self.bot.send_message(m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) return self.bot.send_message(m, self.bot.trans.errors.unknown, extra={'format': 'HTML'}) # Configures a group. # elif is_command(self, 8, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not is_trusted(self.bot, m.sender.id): return self.bot.send_message(m, self.bot.trans.errors.permission_required, extra={'format': 'HTML'}) parameters = [ 'add', 'remove', 'alias', 'description', 'rules', 'rule' ] if not input: text = '<b>Available commands:</b>' for param in parameters: text += '\n • %scfg %s' % (self.bot.config.prefix, param) return self.bot.send_message(m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) if first_word(input) == 'add': if not gid in self.administration: self.administration[gid] = { 'alias': None, 'description': None, 'link': None, 'rules': [] } self.administration.store_database() return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.added % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.already_added % m.conversation.title, extra={'format': 'HTML'}) elif first_word(input) == 'remove': if gid in self.administration: del(self.administration[gid]) self.administration.store_database() return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.removed % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) elif first_word(input) == 'alias': if gid in self.administration: self.administration[gid]['alias'] = all_but_first_word(input) self.administration.store_database() return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) elif first_word(input) == 'description': if gid in self.administration: self.administration[gid]['description'] = all_but_first_word(input) self.administration.store_database() return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) elif first_word(input) == 'link': if gid in self.administration: self.administration[gid]['link'] = all_but_first_word(input) self.administration.store_database() return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) elif first_word(input) == 'rules': if gid in self.administration: self.administration[gid]['rules'] = all_but_first_word(input).split('\n')[0:] self.administration.store_database() return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) elif first_word(input) == 'rule': if gid in self.administration: try: i = int(first_word(all_but_first_word(input)))-1 if i > len(self.administration[gid]['rules']): i = len(self.administration[gid]['rules']) elif i < 1: i = 0 except: return self.bot.send_message(m, self.bot.trans.errors.unknown, extra={'format': 'HTML'}) self.administration[gid]['rules'].insert(i, all_but_first_word(all_but_first_word(input))) self.administration.store_database() return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message(m, self.bot.trans.errors.no_results, extra={'format': 'HTML'}) return self.bot.send_message(m, self.bot.trans.errors.unknown, extra={'format': 'HTML'})
def run(self, m): # List # if is_command(self, 1, m.content): resends = [] forwards = [] text = '' for gid in self.bot.tags: for tag in self.bot.tags[gid]: if 'resend:' in tag: resends.append('{}:{}'.format(gid, tag.split(':')[1])) if 'fwd:' in tag: resends.append('{}:{}'.format(gid, tag.split(':')[1])) if len(resends) > 0: text += '<b>Resends:</b>' text += self.generate_text(resends) if len(forwards) > 0: text += '\n<b>Forwards:</b>' text += self.generate_text(forwards) return self.bot.send_message(m, text, extra={'format': 'HTML'}) # Add resend # elif is_command(self, 2, m.content): input = get_input(m) if not input: return self.bot.send_message(m, generate_command_help( self, m.content), extra={'format': 'HTML'}) origin = first_word(input) destination = first_word(input, 2) if not origin or not destination: return self.bot.send_message(m, generate_command_help( self, m.content), extra={'format': 'HTML'}) # Remove all resends # elif is_command(self, 3, m.content): input = get_input(m) if not input: return self.bot.send_message(m, generate_command_help( self, m.content), extra={'format': 'HTML'}) origin = first_word(input) if not is_int(origin): return self.bot.send_message(m, generate_command_help( self, m.content), extra={'format': 'HTML'}) del_tag(self.bot, origin, 'resend:?') del_tag(self.bot, origin, 'fwd:?') return self.bot.send_message(m, '✅', extra={'format': 'HTML'})
def run(self, m): input = get_input(m) uid = str(m.sender.id) gid = str(m.conversation.id) # List all administration commands. # if is_command(self, 1, m.content): text = self.bot.trans.plugins.administration.strings.commands for command in self.commands: # Adds the command and parameters# if command.command == '^new_chat_member$': text += '\n • ' + \ self.bot.trans.plugins.administration.strings.new_chat_member else: text += '\n • ' + \ command.command.replace('/', self.bot.config.prefix) if 'parameters' in command and command.parameters: for parameter in command.parameters: name, required = list(parameter.items())[0] # Bold for required parameters, and italic for optional # if required: text += ' <b><%s></b>' % name else: text += ' [%s]' % name if 'description' in command: text += '\n <i>%s</i>' % command.description else: text += '\n <i>?¿</i>' return self.bot.send_message(m, text, extra={'format': 'HTML'}) # List all groups. # if is_command(self, 2, m.content): text = self.bot.trans.plugins.administration.strings.groups if len(self.bot.administration) > 0: for gid, attr in self.bot.administration.items(): if 'public' in self.bot.administration[ gid] and self.bot.administration[gid].public: if 'link' in self.bot.administration[ gid] and self.bot.config.bindings != 'telegram-cli': text += '\n • <a href="%s">%s</a>' % ( self.bot.administration[gid].link, self.bot.groups[gid].title) else: text += '\n • %s' % self.bot.groups[gid].title if self.bot.administration[gid].alias: text += ' /<b>%s</b>/' % attr.alias else: text = self.bot.trans.plugins.administration.strings.no_groups return self.bot.send_message(m, text, extra={ 'format': 'HTML', 'preview': False }) # Join a group. # elif is_command(self, 3, m.content): if not input: return self.bot.send_message( m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) for id in self.bot.administration: if (input in self.bot.administration or compile('^' + input.lower() + '$').search( self.bot.administration[id].alias.lower()) or compile('^' + input.lower() + '$').search( self.bot.groups[id].title.lower())): gid_to_join = id break if not gid_to_join in self.bot.administration: return self.bot.send_message( m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) text = '<b>%s</b>' % self.bot.groups[gid_to_join].title if self.bot.administration[gid_to_join].motd: text += '\n<i>%s</i>' % self.bot.administration[ gid_to_join].motd text += '\n\n%s' % self.bot.trans.plugins.administration.strings.rules i = 1 if 'rules' in self.bot.administration[gid_to_join]: for rule in self.bot.administration[gid_to_join].rules: text += '\n %s. <i>%s</i>' % (i, rule) i += 1 else: text += '\n%s' % self.bot.trans.plugins.administration.strings.norules # if self.bot.administration[gid_to_join].public: # text += '\n\n%s' % self.bot.trans.plugins.administration.strings.public_group # else: # text += '\n\n%s' % self.bot.trans.plugins.administration.strings.private_group if not self.bot.administration[gid_to_join].link: text += '\n\n%s' % self.bot.trans.plugins.administration.strings.nolink else: text += '\n\n<a href="%s">%s</a>' % ( self.bot.administration[gid_to_join].link, self.bot.trans.plugins.administration.strings.join) return self.bot.send_message(m, text, extra={ 'format': 'HTML', 'preview': False }) # Information about a group. # elif is_command(self, 4, m.content) or is_command(self, 9, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not gid in self.bot.administration: if is_command(self, 4, m.content): return self.bot.send_message( m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) elif is_command(self, 9, m.content): return text = '<b>%s</b>' % self.bot.groups[gid].title if self.bot.administration[gid].motd: text += '\n<i>%s</i>' % self.bot.administration[gid].motd text += '\n\n%s' % self.bot.trans.plugins.administration.strings.rules i = 1 for rule in self.bot.administration[gid].rules: text += '\n %s. <i>%s</i>' % (i, rule) i += 1 if not self.bot.administration[gid].rules: text += '\n%s' % self.bot.trans.plugins.administration.strings.norules # if self.bot.administration[gid].public: # text += '\n\n%s' % self.bot.trans.plugins.administration.strings.public_group # else: # text += '\n\n%s' % self.bot.trans.plugins.administration.strings.private_group if is_command(self, 4, m.content): if not self.bot.administration[gid].link: text += '\n\n%s' % self.bot.trans.plugins.administration.strings.nolink else: text += '\n\n<a href="%s">%s</a>' % ( self.bot.trans.plugins.administration.strings.join, self.bot.administration[gid].link) return self.bot.send_message(m, text, extra={ 'format': 'HTML', 'preview': False }) # Rules of a group. # elif is_command(self, 5, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not gid in self.bot.administration: return self.bot.send_message( m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) if input and is_int(input): try: i = int(input) text = '%s. <i>%s</i>' % ( i, self.bot.administration[gid].rules[i - 1]) except: text = self.bot.trans.plugins.administration.strings.notfound else: text = self.bot.trans.plugins.administration.strings.rules i = 1 for rule in self.bot.administration[gid].rules: text += '\n %s. <i>%s</i>' % (i, rule) i += 1 if not self.bot.administration[gid].rules: text += '\n%s' % self.bot.trans.plugins.administration.strings.norules return self.bot.send_message(m, text, extra={ 'format': 'HTML', 'preview': False }) # Kicks a user. # elif is_command(self, 6, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not is_mod(self.bot, m.sender.id, m.conversation.id): return self.bot.send_message( m, self.bot.trans.errors.permission_required, extra={'format': 'HTML'}) if not input and not m.reply: return self.bot.send_message( m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) if m.reply: target = m.reply.sender.id elif is_int(input): target = input else: target = m.sender.id res = self.bot.kick_user(m, target) self.bot.unban_user(m, target) if res is None: return self.bot.send_message( m, self.bot.trans.errors.admin_required, extra={'format': 'HTML'}) elif not res: return self.bot.send_message(m, self.bot.trans.errors.failed, extra={'format': 'HTML'}) else: return self.bot.send_message( m, '<pre>An enemy has been slain.</pre>', extra={'format': 'HTML'}) return self.bot.send_message(m, self.bot.trans.errors.unknown, extra={'format': 'HTML'}) # Bans a user. # elif is_command(self, 7, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not is_mod(self.bot, m.sender.id, m.conversation.id): return self.bot.send_message( m, self.bot.trans.errors.permission_required, extra={'format': 'HTML'}) if not input: return self.bot.send_message( m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) return self.bot.send_message(m, self.bot.trans.errors.unknown, extra={'format': 'HTML'}) # Configures a group. # elif is_command(self, 8, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not is_mod(self.bot, m.sender.id, m.conversation.id): return self.bot.send_message( m, self.bot.trans.errors.permission_required, extra={'format': 'HTML'}) if not input: self.bot.send_message( m, self.bot.trans.plugins.administration.strings.ask_to_add % m.conversation.title, extra={ 'format': 'HTML', 'force_reply': True }) if not gid in self.bot.administration: self.bot.administration[gid] = { 'alias': None, 'description': None, 'link': None, 'rules': [], 'public': False } set_data('administration/%s/%s' % (self.bot.name, gid), self.bot.administration[gid]) set_step(self.bot, m.conversation.id, get_plugin_name(self), 1) else: if first_word(input) == 'add': if not gid in self.bot.administration: self.bot.administration[gid] = { 'alias': None, 'description': None, 'link': None, 'rules': [], 'public': False } set_data('administration/%s/%s' % (self.bot.name, gid), self.bot.administration[gid]) return self.bot.send_message( m, self.bot.trans.plugins.administration.strings.added % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message( m, self.bot.trans.plugins.administration.strings. already_added % m.conversation.title, extra={'format': 'HTML'}) elif first_word(input) == 'remove': if gid in self.bot.administration: del self.bot.administration[gid] delete_data('administration/%s/%s' % (self.bot.name, gid)) return self.bot.send_message( m, self.bot.trans.plugins.administration.strings. removed % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message( m, self.bot.trans.plugins.administration.strings. not_added % m.conversation.title, extra={'format': 'HTML'}) elif first_word(input) == 'alias': if gid in self.bot.administration: self.bot.administration[ gid].alias = all_but_first_word(input).lower() set_data( 'administration/%s/%s/alias' % (self.bot.name, gid), self.bot.administration[gid].alias) return self.bot.send_message( m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message( m, self.bot.trans.plugins.administration.strings. not_added % m.conversation.title, extra={'format': 'HTML'}) elif first_word(input) == 'motd': if gid in self.bot.administration: self.bot.administration[gid].motd = all_but_first_word( input) set_data( 'administration/%s/%s/motd' % (self.bot.name, gid), self.bot.administration[gid].motd) return self.bot.send_message( m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message( m, self.bot.trans.plugins.administration.strings. not_added % m.conversation.title, extra={'format': 'HTML'}) elif first_word(input) == 'link': if gid in self.bot.administration: self.bot.administration[gid].link = all_but_first_word( input) set_data( 'administration/%s/%s/link' % (self.bot.name, gid), self.bot.administration[gid].link) return self.bot.send_message( m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message( m, self.bot.trans.plugins.administration.strings. not_added % m.conversation.title, extra={'format': 'HTML'}) elif first_word(input) == 'rules': if gid in self.bot.administration: self.bot.administration[ gid].rules = all_but_first_word( all_but_first_word(input).split('\n')[0:]) set_data( 'administration/%s/%s/rules' % (self.bot.name, gid), self.bot.administration[gid].rules) return self.bot.send_message( m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message( m, self.bot.trans.plugins.administration.strings. not_added % m.conversation.title, extra={'format': 'HTML'}) elif first_word(input) == 'rule': if gid in self.bot.administration: try: i = int(first_word(all_but_first_word(input))) - 1 if i > len(self.bot.administration[gid].rules): i = len(self.bot.administration[gid].rules) elif i < 1: i = 0 except: return self.bot.send_message( m, self.bot.trans.errors.unknown, extra={'format': 'HTML'}) self.bot.administration[gid].rules.insert( i, all_but_first_word(all_but_first_word(input))) set_data( 'administration/%s/%s/rules' % (self.bot.name, gid), self.bot.administration[gid].rules) return self.bot.send_message( m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message( m, self.bot.trans.plugins.administration.strings. not_added % m.conversation.title, extra={'format': 'HTML'}) elif first_word(input) == 'public': if gid in self.bot.administration: if self.bot.trans.plugins.administration.strings.yes.lower( ) in all_but_first_word(input).lower(): self.bot.administration[gid].public = True else: self.bot.administration[gid].public = False set_data( 'administration/%s/%s/public' % (self.bot.name, gid), self.bot.administration[gid].public) return self.bot.send_message( m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message( m, self.bot.trans.plugins.administration.strings. not_added % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message( m, self.bot.trans.errors.no_results, extra={'format': 'HTML'})
def run(self, m): input = get_input(m) uid = str(m.sender.id) gid = str(m.conversation.id) # List all administration commands. # if is_command(self, 1, m.content): text = self.bot.trans.plugins.administration.strings.commands for command in self.commands: # Adds the command and parameters# if command['command'] == '^new_chat_member$': text += '\n • ' + self.bot.trans.plugins.administration.strings.new_chat_member else: text += '\n • ' + command['command'].replace( '/', self.bot.config.prefix) if 'parameters' in command: for parameter in command['parameters']: name, required = list(parameter.items())[0] # Bold for required parameters, and italic for optional # if required: text += ' <b><%s></b>' % name else: text += ' [%s]' % name if 'description' in command: text += '\n <i>%s</i>' % command['description'] else: text += '\n <i>?¿</i>' return self.bot.send_message(m, text, extra={'format': 'HTML'}) # List all groups. # if is_command(self, 2, m.content): text = self.bot.trans.plugins.administration.strings.groups i = 1 for gid, attr in self.administration.items(): text += '\n %s. %s (%s)' % (i, self.groups[gid]['title'], attr['alias']) i += 1 return self.bot.send_message(m, text, extra={'format': 'HTML'}) # Send message to another group. # if is_command(self, 10, m.content): input = get_input(m, ignore_reply=False) if not input: return self.bot.send_message( m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) id_backup = m.conversation.id group_number = int(findall(r"(\w+)", m.content)[1]) msg_offset = len(str(group_number)) + 1 text = input[msg_offset:] if text and is_int(group_number): m.conversation.id = 0 for gid in self.administration: if group_number == 1: m.conversation.id = int(gid) group_number -= 1 if m.conversation.id != id_backup and m.conversation.id != 0: text = self.bot.trans.plugins.administration.strings.message_received % m.conversation.title + text return self.bot.send_message(m, text, extra={'format': 'HTML'}) #return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.sent, extra={'format': 'HTML'}) elif m.conversation.id == id_backup: return self.bot.send_message( m, self.bot.trans.plugins.administration.strings.no_echo, extra={'format': 'HTML'}) else: m.conversation.id = id_backup return self.bot.send_message( m, self.bot.trans.errors.send_error, extra={'format': 'HTML'}) else: return self.bot.send_message( m, self.bot.trans.plugins.administration.strings. invalid_syntax, extra={'format': 'HTML'}) # Join a group. # elif is_command(self, 3, m.content): if not input: return self.bot.send_message( m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) for id in self.administration: if (input in self.administration or input in self.administration[id]['alias'] or input in self.groups[id]['title']): gid_to_join = id break if not gid_to_join in self.administration: return self.bot.send_message( m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) text = '<b>%s</b>\n<i>%s</i>\n\n%s' % ( self.groups[gid_to_join]['title'], self.administration[gid_to_join]['description'], self.bot.trans.plugins.administration.strings.rules) i = 1 for rule in self.administration[gid_to_join]['rules']: text += '\n %s. <i>%s</i>' % (i, rule) i += 1 if not self.administration[gid_to_join]['rules']: text += '\n%s' % self.bot.trans.plugins.administration.strings.norules if not self.administration[gid_to_join]['link']: text += '\n\n%s' % self.bot.trans.plugins.administration.strings.nolink else: text += '\n\n<a href="%s">%s</a>' % ( self.administration[gid_to_join]['link'], self.bot.trans.plugins.administration.strings.join) return self.bot.send_message(m, text, extra={ 'format': 'HTML', 'preview': False }) # Information about a group. # elif is_command(self, 4, m.content) or is_command(self, 9, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not gid in self.administration: if is_command(self, 4, m.content): return self.bot.send_message( m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) elif is_command(self, 9, m.content): return text = '<b>%s</b>\n<i>%s</i>\n\n%s' % ( self.groups[gid]['title'], self.administration[gid]['description'], self.bot.trans.plugins.administration.strings.rules) i = 1 for rule in self.administration[gid]['rules']: text += '\n %s. <i>%s</i>' % (i, rule) i += 1 if not self.administration[gid]['rules']: text += '\n%s' % self.bot.trans.plugins.administration.strings.norules if is_command(self, 4, m.content): if not self.administration[gid]['link']: text += '\n\n%s' % self.bot.trans.plugins.administration.strings.nolink else: text += '\n\n<a href="%s">%s</a>' % ( self.bot.trans.plugins.administration.strings.join. self.administration[gid]['link']) return self.bot.send_message(m, text, extra={ 'format': 'HTML', 'preview': False }) # Rules of a group. # elif is_command(self, 5, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not gid in self.administration: return self.bot.send_message( m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) if input and is_int(input): try: i = int(input) text = '%s. <i>%s</i>' % ( i, self.administration[gid]['rules'][i - 1]) except: text = self.bot.trans.plugins.administration.strings.notfound else: text = self.bot.trans.plugins.administration.strings.rules i = 1 for rule in self.administration[gid]['rules']: text += '\n %s. <i>%s</i>' % (i, rule) i += 1 if not self.administration[gid]['rules']: text += '\n%s' % self.bot.trans.plugins.administration.strings.norules return self.bot.send_message(m, text, extra={ 'format': 'HTML', 'preview': False }) # Kicks a user. # elif is_command(self, 6, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not is_mod(self.bot, m.sender.id, m.conversation.id): return self.bot.send_message( m, self.bot.trans.errors.permission_required, extra={'format': 'HTML'}) if not input and not m.reply: return self.bot.send_message( m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) if m.reply: target = m.reply.sender.id elif input: target = input else: target = m.sender.id res = self.bot.kick_user(m, target) self.bot.unban_user(m, target) if res is None: return self.bot.send_message( m, self.bot.trans.errors.admin_required, extra={'format': 'HTML'}) elif not res: return self.bot.send_message(m, self.bot.trans.errors.failed, extra={'format': 'HTML'}) else: return self.bot.send_message( m, '<pre>An enemy has been slain.</pre>', extra={'format': 'HTML'}) return self.bot.send_message(m, self.bot.trans.errors.unknown, extra={'format': 'HTML'}) # Bans a user. # elif is_command(self, 7, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not is_mod(self.bot, m.sender.id, m.conversation.id): return self.bot.send_message( m, self.bot.trans.errors.permission_required, extra={'format': 'HTML'}) if not input: return self.bot.send_message( m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) return self.bot.send_message(m, self.bot.trans.errors.unknown, extra={'format': 'HTML'}) # Configures a group. # elif is_command(self, 8, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not is_mod(self.bot, m.sender.id, m.conversation.id): return self.bot.send_message( m, self.bot.trans.errors.permission_required, extra={'format': 'HTML'}) if not input: self.bot.send_message( m, self.bot.trans.plugins.administration.strings.ask_to_add % m.conversation.title, extra={ 'format': 'HTML', 'force_reply': True }) if not gid in self.administration: self.administration[gid] = { 'alias': None, 'description': None, 'link': None, 'rules': [] } self.administration.store_database() set_step(self.bot, m.conversation.id, get_plugin_name(self), 1) else: if first_word(input) == 'add': if not gid in self.administration: self.administration[gid] = { 'alias': None, 'description': None, 'link': None, 'rules': [] } self.administration.store_database() return self.bot.send_message( m, self.bot.trans.plugins.administration.strings.added % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message( m, self.bot.trans.plugins.administration.strings. already_added % m.conversation.title, extra={'format': 'HTML'}) elif first_word(input) == 'remove': if gid in self.administration: del (self.administration[gid]) self.administration.store_database() return self.bot.send_message( m, self.bot.trans.plugins.administration.strings. removed % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message( m, self.bot.trans.plugins.administration.strings. not_added % m.conversation.title, extra={'format': 'HTML'}) elif first_word(input) == 'alias': if gid in self.administration: self.administration[gid]['alias'] = all_but_first_word( input) self.administration.store_database() return self.bot.send_message( m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message( m, self.bot.trans.plugins.administration.strings. not_added % m.conversation.title, extra={'format': 'HTML'}) elif first_word(input) == 'motd': if gid in self.administration: self.administration[gid][ 'description'] = all_but_first_word(input) self.administration.store_database() return self.bot.send_message( m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message( m, self.bot.trans.plugins.administration.strings. not_added % m.conversation.title, extra={'format': 'HTML'}) elif first_word(input) == 'link': if gid in self.administration: self.administration[gid]['link'] = all_but_first_word( input) self.administration.store_database() return self.bot.send_message( m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message( m, self.bot.trans.plugins.administration.strings. not_added % m.conversation.title, extra={'format': 'HTML'}) elif first_word(input) == 'rules': if gid in self.administration: self.administration[gid]['rules'] = all_but_first_word( input).split('\n')[0:] self.administration.store_database() return self.bot.send_message( m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message( m, self.bot.trans.plugins.administration.strings. not_added % m.conversation.title, extra={'format': 'HTML'}) elif first_word(input) == 'rule': if gid in self.administration: try: i = int(first_word(all_but_first_word(input))) - 1 if i > len(self.administration[gid]['rules']): i = len(self.administration[gid]['rules']) elif i < 1: i = 0 except: return self.bot.send_message( m, self.bot.trans.errors.unknown, extra={'format': 'HTML'}) self.administration[gid]['rules'].insert( i, all_but_first_word(all_but_first_word(input))) self.administration.store_database() return self.bot.send_message( m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message( m, self.bot.trans.plugins.administration.strings. not_added % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message( m, self.bot.trans.errors.no_results, extra={'format': 'HTML'})
def run(self, m): input = get_input(m) text = None if m.reply: uid = str(m.reply.sender.id) else: uid = str(m.sender.id) # Get character data if is_command(self, 1, m.content): summoner_name = None if not input: tags = has_tag(self.bot, m.sender.id, 'lol:?', return_match=True) if tags and len(tags) > 0: summoner_info = tags[0].split(':')[1] if ('/' in summoner_info): self.region = self.regions[summoner_info.split('/')[0]] summoner_name = summoner_info.split('/')[1] if not summoner_name: return self.bot.send_message(m, generate_command_help( self, m.content), extra={'format': 'HTML'}) else: if first_word(input).lower() in self.regions: self.region = self.regions[first_word(input).lower()] summoner_name = all_but_first_word(input) else: self.region = self.regions['euw'] summoner_name = input summoner = self.summoner_by_name(summoner_name) if not summoner or 'status' in summoner and summoner['status'][ 'status_code'] != 200: return self.bot.send_message( m, self.bot.trans.errors.connection_error, extra={'format': 'HTML'}) account = self.account_by_puuid(summoner.puuid) masteries = self.champion_masteries(summoner.id) ranked = self.league_entries(summoner.id) if self.latest_version: icon_url = "http://ddragon.leagueoflegends.com/cdn/{}/img/profileicon/{}.png".format( self.latest_version, summoner.profileIconId) else: icon_url = None opgg_region = self.region[ 'platform'] if self.region['platform'] != 'kr' else 'www' opgg = 'http://{}.op.gg/summoner/userName={}'.format( opgg_region, ''.join(summoner_name.split())) text = '{} (Lv: {})\n'.format(summoner.name, summoner.summonerLevel) if account and 'gameName' in account: text += '{}\n'.format(account.gameName + '#' + account.tagLine) if masteries: text += '\nMasteries:' for mastery in masteries[:5]: text += '\n\t{}: Lv {} ({}k)'.format( self.championIds[str(mastery['championId'])], mastery['championLevel'], int(mastery['championPoints'] / 1000)) if ranked: for queue in ranked: text += '\n\n{}:\n\tLeague: {} {} ({}LP)'.format( self.ranked_queueType(queue['queueType']), self.ranked_tier(queue['tier']), queue['rank'], queue['leaguePoints']) text += '\n\tWins/Losses: {} / {} ({}%)'.format( queue['wins'], queue['losses'], str( int((float(queue['wins']) / (float(queue['wins']) + float(queue['losses']))) * 100)).replace( '.', '\'')) # text += '\n\n<a href="{}">{}</a>'.format(opgg, 'OP.GG') if icon_url: return self.bot.send_message(m, icon_url, 'photo', extra={ 'caption': text, 'format': 'HTML', 'preview': True }) return self.bot.send_message(m, text, extra={ 'format': 'HTML', 'preview': True })
def run(self, m): input = get_input(m) uid = str(m.sender.id) gid = str(m.conversation.id) # List all administration commands. # if is_command(self, 1, m.content): return self.bot.send_message(m, self.bot.trans.errors.unknown, extra={'format': 'HTML'}) # List all groups. # if is_command(self, 2, m.content): return self.bot.send_message(m, self.bot.trans.errors.unknown, extra={'format': 'HTML'}) # Join a group. # elif is_command(self, 3, m.content): if not input: return self.bot.send_message(m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) return self.bot.send_message(m, self.bot.trans.errors.unknown, extra={'format': 'HTML'}) # Information about a group. # elif is_command(self, 4, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) return self.bot.send_message(m, self.bot.trans.errors.unknown, extra={'format': 'HTML'}) # Rules of a group. # elif is_command(self, 5, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) return self.bot.send_message(m, self.bot.trans.errors.unknown, extra={'format': 'HTML'}) # Kicks a user. # elif is_command(self, 6, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not is_mod(self.bot, m.sender.id, m.conversation.id): return self.bot.send_message(m, self.bot.trans.errors.permission_required, extra={'format': 'HTML'}) if not input: return self.bot.send_message(m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) return self.bot.send_message(m, self.bot.trans.errors.unknown, extra={'format': 'HTML'}) # Bans a user. # elif is_command(self, 7, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not is_mod(self.bot, m.sender.id, m.conversation.id): return self.bot.send_message(m, self.bot.trans.errors.permission_required, extra={'format': 'HTML'}) if not input: return self.bot.send_message(m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) return self.bot.send_message(m, self.bot.trans.errors.unknown, extra={'format': 'HTML'}) # Configures a group. # elif is_command(self, 8, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not is_trusted(self.bot, m.sender.id, m.conversation.id): return self.bot.send_message(m, self.bot.trans.errors.permission_required, extra={'format': 'HTML'}) if not input: return self.bot.send_message(m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) if first_word(input) == 'add': if not gid in self.administration: self.administration[gid] return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.added % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.already_added % m.conversation.title, extra={'format': 'HTML'}) elif first_word(input) == 'remove': if gid in self.administration: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.removed % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) elif first_word(input) == 'alias': if gid in self.administration: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) elif first_word(input) == 'description': if gid in self.administration: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) elif first_word(input) == 'rules': if gid in self.administration: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) elif first_word(input) == 'rule': if str(m.conversation.id) in self.administration: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message(m, self.bot.trans.errors.no_results, extra={'format': 'HTML'}) return self.bot.send_message(m, self.bot.trans.errors.unknown, extra={'format': 'HTML'})
def run(self, m): input = get_input(m) uid = str(m.sender.id) gid = str(m.conversation.id) # List all administration commands. # if is_command(self, 1, m.content): text = self.bot.trans.plugins.administration.strings.commands for command in self.commands: # Adds the command and parameters# if command.command == '^new_chat_member$': text += '\n • ' + \ self.bot.trans.plugins.administration.strings.new_chat_member else: text += '\n • ' + \ command.command.replace('/', self.bot.config.prefix) if 'parameters' in command and command.parameters: for parameter in command.parameters: name, required = list(parameter.items())[0] # Bold for required parameters, and italic for optional # if required: text += ' <b><%s></b>' % name else: text += ' [%s]' % name if 'description' in command: text += '\n <i>%s</i>' % command.description else: text += '\n <i>?¿</i>' return self.bot.send_message(m, text, extra={'format': 'HTML'}) # List all groups. # if is_command(self, 2, m.content): text = self.bot.trans.plugins.administration.strings.groups if len(self.bot.administration) > 0: for gid, attr in self.bot.administration.items(): if 'public' in self.bot.administration[gid] and self.bot.administration[gid].public: if 'link' in self.bot.administration[gid] and self.bot.config.bindings != 'telegram-cli': text += '\n • <a href="%s">%s</a>' % ( self.bot.administration[gid].link, self.bot.groups[gid].title) else: text += '\n • %s' % self.bot.groups[gid].title if self.bot.administration[gid].alias: text += ' /<b>%s</b>/' % attr.alias else: text = self.bot.trans.plugins.administration.strings.no_groups return self.bot.send_message(m, text, extra={'format': 'HTML', 'preview': False}) # Join a group. # elif is_command(self, 3, m.content): if not input: return self.bot.send_message(m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) gid_to_join = None for id in self.bot.administration: if (input in self.bot.administration or compile('^' + input.lower() + '$').search(self.bot.administration[id].alias.lower()) or compile('^' + input.lower() + '$').search(self.bot.groups[id].title.lower())): gid_to_join = id break if gid_to_join: if not gid_to_join in self.bot.administration: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) added = self.bot.bindings.invite_conversation_member( gid_to_join, uid) if not added: text = '<b>%s</b>' % self.bot.groups[gid_to_join].title if self.bot.administration[gid_to_join].motd: text += '\n<i>%s</i>' % self.bot.administration[gid_to_join].motd text += '\n\n%s' % self.bot.trans.plugins.administration.strings.rules i = 1 if 'rules' in self.bot.administration[gid_to_join]: for rule in self.bot.administration[gid_to_join].rules: text += '\n %s. <i>%s</i>' % (i, rule) i += 1 else: text += '\n%s' % self.bot.trans.plugins.administration.strings.norules if not self.bot.administration[gid_to_join].link: text += '\n\n%s' % self.bot.trans.plugins.administration.strings.nolink else: text += '\n\n<a href="%s">%s</a>' % ( self.bot.administration[gid_to_join].link, self.bot.trans.plugins.administration.strings.join) return self.bot.send_message(m, text, extra={'format': 'HTML', 'preview': False}) # Information about a group. # elif is_command(self, 4, m.content) or is_command(self, 16, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not gid in self.bot.administration: if is_command(self, 4, m.content): return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) elif is_command(self, 16, m.content): return text = '<b>%s</b>' % self.bot.groups[gid].title if 'motd' in self.bot.administration[gid]: text += '\n<i>%s</i>' % self.bot.administration[gid].motd text += '\n\n%s' % self.bot.trans.plugins.administration.strings.rules i = 1 if not 'rules' in self.bot.administration[gid]: text += '\n%s' % self.bot.trans.plugins.administration.strings.norules else: for rule in self.bot.administration[gid].rules: text += '\n %s. <i>%s</i>' % (i, rule) i += 1 if is_command(self, 4, m.content): if not self.bot.administration[gid].link: text += '\n\n%s' % self.bot.trans.plugins.administration.strings.nolink else: text += '\n\n<a href="%s">%s</a>' % ( self.bot.trans.plugins.administration.strings.join, self.bot.administration[gid].link) return self.bot.send_message(m, text, extra={'format': 'HTML', 'preview': False}) # Rules of a group. # elif is_command(self, 5, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not gid in self.bot.administration: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) if input and is_int(input): try: i = int(input) text = '%s. <i>%s</i>' % (i, self.bot.administration[gid].rules[i - 1]) except: text = self.bot.trans.plugins.administration.strings.notfound else: text = self.bot.trans.plugins.administration.strings.rules i = 1 for rule in self.bot.administration[gid].rules: text += '\n %s. <i>%s</i>' % (i, rule) i += 1 if not self.bot.administration[gid].rules: text += '\n%s' % self.bot.trans.plugins.administration.strings.norules return self.bot.send_message(m, text, extra={'format': 'HTML', 'preview': False}) # Set rules # elif is_command(self, 6, m.content): if not input: return self.bot.send_message(m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not is_admin(self.bot, uid, m) and not is_mod(self.bot, uid, gid): return self.bot.send_message(m, self.bot.trans.errors.permission_required, extra={'format': 'HTML'}) if gid in self.bot.administration: self.bot.administration[gid].rules = input.split('\n') set_data('administration/%s/%s/rules' % (self.bot.name, gid), self.bot.administration[gid].rules) return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) # Set rule # elif is_command(self, 7, m.content): if not input: return self.bot.send_message(m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not is_admin(self.bot, uid, m) and not is_mod(self.bot, uid, gid): return self.bot.send_message(m, self.bot.trans.errors.permission_required, extra={'format': 'HTML'}) if gid in self.bot.administration: try: i = int(first_word(input))-1 if i > len(self.bot.administration[gid].rules): i = len(self.bot.administration[gid].rules) elif i < 1: i = 0 except: return self.bot.send_message(m, self.bot.trans.errors.invalid_syntax, extra={'format': 'HTML'}) self.bot.administration[gid].rules.insert( i, all_but_first_word(input)) set_data('administration/%s/%s/rules' % (self.bot.name, gid), self.bot.administration[gid].rules) return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) # Remove rule # elif is_command(self, 8, m.content): if not input: return self.bot.send_message(m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not is_admin(self.bot, uid, m) and not is_mod(self.bot, uid, gid): return self.bot.send_message(m, self.bot.trans.errors.permission_required, extra={'format': 'HTML'}) if gid in self.bot.administration: try: i = int(first_word(input))-1 if i > len(self.bot.administration[gid].rules): i = len(self.bot.administration[gid].rules) elif i < 1: i = 0 except: return self.bot.send_message(m, self.bot.trans.errors.invalid_syntax, extra={'format': 'HTML'}) del self.bot.administration[gid].rules[i] set_data('administration/%s/%s/rules' % (self.bot.name, gid), self.bot.administration[gid].rules) return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) # Add mod # elif is_command(self, 9, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not is_admin(self.bot, uid, m): return self.bot.send_message(m, self.bot.trans.errors.permission_required, extra={'format': 'HTML'}) set_tag(self.bot, m.sender.id, 'mod:%s' % gid) # Remove mod # elif is_command(self, 10, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not is_admin(self.bot, uid, gid): return self.bot.send_message(m, self.bot.trans.errors.permission_required, extra={'format': 'HTML'}) del_tag(self.bot, m.sender.id, 'mod:%s' % gid) # Add group # elif is_command(self, 11, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not is_admin(self.bot, uid, m): return self.bot.send_message(m, self.bot.trans.errors.permission_required, extra={'format': 'HTML'}) if not gid in self.bot.administration: self.bot.administration[gid] = { 'alias': None, 'description': None, 'link': None, 'rules': [], 'public': False } set_data('administration/%s/%s' % (self.bot.name, gid), self.bot.administration[gid]) return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.added % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.already_added % m.conversation.title, extra={'format': 'HTML'}) # Remove group # elif is_command(self, 12, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not is_admin(self.bot, uid, m): return self.bot.send_message(m, self.bot.trans.errors.permission_required, extra={'format': 'HTML'}) if gid in self.bot.administration: del self.bot.administration[gid] delete_data('administration/%s/%s' % (self.bot.name, gid)) return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.removed % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) # Set alias # elif is_command(self, 13, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not is_admin(self.bot, uid, m): return self.bot.send_message(m, self.bot.trans.errors.permission_required, extra={'format': 'HTML'}) if gid in self.bot.administration: self.bot.administration[gid].alias = input.lower() set_data('administration/%s/%s/alias' % (self.bot.name, gid), self.bot.administration[gid].alias) return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) # Set link # elif is_command(self, 14, m.content): if m.conversation.id > 0: return self.bot.send_message(m, self.bot.trans.errors.group_only, extra={'format': 'HTML'}) if not is_admin(self.bot, uid, m): return self.bot.send_message(m, self.bot.trans.errors.permission_required, extra={'format': 'HTML'}) if gid in self.bot.administration: self.bot.administration[gid].link = input.lower() set_data('administration/%s/%s/link' % (self.bot.name, gid), self.bot.administration[gid].link) return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'}) # Make public # elif is_command(self, 15, m.content): if not input: return self.bot.send_message(m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'}) if gid in self.bot.administration: if input and 'true' in input.lower(): self.bot.administration[gid].public = True else: self.bot.administration[gid].public = False set_data('administration/%s/%s/public' % (self.bot.name, gid), self.bot.administration[gid].public) return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.set % m.conversation.title, extra={'format': 'HTML'}) else: return self.bot.send_message(m, self.bot.trans.plugins.administration.strings.not_added % m.conversation.title, extra={'format': 'HTML'})