Ejemplo n.º 1
0
 def _on_message_(self, event, bot):
     text = utils.decode_text(event.text)
     command_raw = utils.try_remove_prefix(text, event.peer_id)
     if len(command_raw) != len(text):
         command_raw = command_raw.split()
         command = None
         try:
             command = bot.get_command(event, command_raw[0])
             if bot.PERMISSIONS.have_permission(event,
                                                command.get_permission()):
                 line = " ".join(command_raw[1:])
                 command.run(event, bot, utils.decode_quot(line),
                             shlex.split(line))
                 return True
             else:
                 vkrine.MessageBuilder().translated_text(
                     "commands.generic.permission").send(event)
         except exceptions.CommandWrongUsageException:
             message = bot.L10N.translate(event, command.get_help())
             vkrine.MessageBuilder().translated_text(
                 "commands.generic.usage", message).send(event)
         except exceptions.CommandException as e:
             vkrine.MessageBuilder().translated_text(
                 e.get_message(), *e.get_args(),
                 **e.get_kwargs()).send(event)
         except Exception as e:
             vkrine.MessageBuilder().translated_text(
                 "commands.generic.exception", e).send(event)
             traceback.print_exc()
Ejemplo n.º 2
0
 def run(self, event, bot, line, args):
     self.__init_pages_lazy__(bot)
     page = 1
     pages = len(self.__pages__)
     command_name = None
     if len(args) > 0:
         try:
             page = parse_int_bounded(args[0], 1, pages)
         except exceptions.NumberInvalidException:
             command_name = args[0]
     if command_name:
         command = bot.get_command(event, command_name)
         aliases = bot.L10N.translate_list(event, command.get_aliases_key())
         aliases.remove(command.get_aliases_key())
         aliases = "', '".join(aliases)
         if not aliases:
             aliases = bot.L10N.translate(event, "commands.none")
         else:
             aliases = "'{}'".format(aliases)
         vkrine.MessageBuilder().translated_text(
             command.get_help_extended()).newline(2).translated_text(
                 "help.aliases", aliases).send(event)
     else:
         page_data = []
         for command in self.__pages__[page - 1]:
             text = "{} - {}".format(
                 command.NAME, bot.L10N.translate(event,
                                                  command.get_help()))
             page_data.append(text)
         page = utils.emoji_numbers(page)
         pages = utils.emoji_numbers(pages)
         vkrine.MessageBuilder().translated_text(
             "help.page", page, pages, "\n".join(page_data)).send(event)
Ejemplo n.º 3
0
 def run(self):
     for event in VkLongPoll(self.__session__).check():
         if not event:
             continue
         try:
             for listener in self._listeners_:
                 if self.SETTINGS.get_option("multithreading", False):
                     self._EXECUTOR_.submit(listener.on_event, event, self)
                 else:
                     listener.on_event(event, self)
         except Captcha as captcha1:
             file_captcha = self.RUNTIME + "/captcha.jpg"
             with open(file_captcha, "wb") as handle:
                 response = requests.get(captcha1.url, stream=True)
                 for block in response.iter_content(1024):
                     if not block:
                         break
                 handle.write(block)
                 try:
                     photo = self.get_upload().photo_messages(
                         file_captcha)[0]
                     attachment = "photo{}_{}".format(
                         photo["owner_id"], photo["id"])
                     vkrine.MessageBuilder().translated_text(
                         "text.captcha",
                         captcha1.url).attachment(attachment).send(event)
                     self.current_captcha = captcha1
                 except Captcha as captcha2:
                     vkrine.severe("Captcha",
                                   "Required captcha, see {}/captcha.jpg",
                                   self.RUNTIME)
                     answer = input("Answer: ")
                     captcha2.try_again(answer)
                     vkrine.info("Captcha", "Captcha solved")
Ejemplo n.º 4
0
 def _on_message_(self, event, bot):
     marker = bot.SETTINGS.get_option("modules.stickers.marker", default=":", chat_id=event.peer_id)
     temp = utils.try_remove_prefix(event.text, event.peer_id)
     if temp == event.text:
         for word in re.findall(marker + r'([а-яёa-z0-9._();]+)' + marker, utils.decode_text(event.text),
                                re.IGNORECASE):
             sticker = self._MODULE_.get_sticker(event, word)
             if sticker:
                 if bot.PERMISSIONS.have_permission(event, "stickers.{}".format(word)):
                     vkrine.MessageBuilder().append_attachment(sticker).send(event)
                     break
Ejemplo n.º 5
0
 def run(self, event, bot, line, args):
     if len(args) == 1:
         answer = args[0]
         if bot.current_captcha:
             bot.current_captcha.try_again(answer)
             done(event)
             bot.current_captcha = None
         else:
             vkrine.MessageBuilder().translated_text(
                 "text.captcha.none").send(event)
     else:
         raise exceptions.CommandWrongUsageException(None)
Ejemplo n.º 6
0
 def run(self, event, bot, line, args):
     if args:
         s = len(args)
         min_roll = 0
         if s == 1:
             max_roll = cmds.parse_int(args[0])
         elif s == 2:
             min_roll = cmds.parse_int(args[0])
             max_roll = cmds.parse_int(args[1])
             if min_roll >= max_roll:
                 raise exceptions.CommandSyntaxError(
                     "commands.text.roll.bad_range")
         else:
             raise exceptions.CommandWrongUsageException(None)
         roll = random.randint(min_roll, max_roll)
         vkrine.MessageBuilder().translated_text("commands.text.roll",
                                                 roll).send(event)
     else:
         roll = random.randint(0, 100)
         vkrine.MessageBuilder().translated_text("commands.text.roll",
                                                 roll).send(event)
Ejemplo n.º 7
0
def done(event):
    vkrine.MessageBuilder().translated_text("commands.done").send(event)
Ejemplo n.º 8
0
 def run(self, event, bot, line, args):
     s = len(args)
     if s == 0:
         raise exceptions.CommandWrongUsageException(None)
     if is_arg(event, "global", self.get_arg_key("global"), args[0]):
         have_permission(event, self.get_arg_permission("global"))
         if s == 2:
             locale = args[1]
             if locale == "default":
                 bot.L10N.set_locale("@main", "en_US")
                 done(event)
             elif bot.L10N.has_locale(locale):
                 bot.L10N.set_locale("@main", locale)
                 done(event)
             else:
                 vkrine.MessageBuilder().translated_text(
                     "commands.text.locale.not_found", locale).send(event)
         elif s == 1:
             locale = bot.L10N.get_locale_key("@main")
             vkrine.MessageBuilder().translated_text(
                 "commands.text.locale.current", locale).send(event)
         else:
             raise exceptions.CommandWrongUsageException(None)
     elif is_arg(event, "chat", self.get_arg_key("chat"), args[0]):
         have_permission(event, self.get_arg_permission("chat"))
         if s == 2:
             locale = args[1]
             if locale == "default":
                 bot.L10N.reset_locale(str(event.peer_id))
                 done(event)
             elif bot.L10N.has_locale(locale):
                 bot.L10N.set_locale(str(event.peer_id), locale)
                 done(event)
             else:
                 vkrine.MessageBuilder().translated_text(
                     "commands.text.locale.not_found", locale).send(event)
         elif s == 1:
             locale = bot.L10N.get_locale_key(event.peer_id)
             vkrine.MessageBuilder().translated_text(
                 "commands.text.locale.current", locale).send(event)
         else:
             raise exceptions.CommandWrongUsageException(None)
     elif is_arg(event, "personal", self.get_arg_key("personal"), args[0]):
         have_permission(event, self.get_arg_permission("personal"))
         if s == 2:
             locale = args[1]
             if locale == "default":
                 bot.L10N.reset_locale(str(event.user_id))
                 done(event)
             elif bot.L10N.has_locale(locale):
                 bot.L10N.set_locale(str(event.user_id), locale)
                 done(event)
             else:
                 vkrine.MessageBuilder().translated_text(
                     "commands.text.locale.not_found", locale).send(event)
         elif s == 1:
             locale = bot.L10N.get_locale_key(event.user_id)
             vkrine.MessageBuilder().translated_text(
                 "commands.text.locale.current", locale).send(event)
         else:
             raise exceptions.CommandWrongUsageException(None)
     elif is_arg(event, "list", self.get_arg_key("list"), args[0]):
         if s == 1:
             vkrine.MessageBuilder().translated_text(
                 "commands.text.locale.list",
                 ", ".join(bot.L10N.locales())).send(event)
         else:
             raise exceptions.CommandWrongUsageException(None)
     else:
         raise exceptions.CommandWrongUsageException(None)
Ejemplo n.º 9
0
 def run(self, event, bot, line, args):
     vkrine.MessageBuilder(bash_im_random_quote()).send(event)
Ejemplo n.º 10
0
 def run(self, event, bot, line, args):
     vkrine.MessageBuilder(line).send(event)