def update_handler(bot, update):
    try:
        infos = Infos.Infos(bot, update)
        if infos.error:
            return Log.d("Errore owo!")

        if infos.user.uid in json.loads(open("Files/jsons/blacklist.json").read()) or infos.skip:
            return

        if "message" in update:
            if "new_chat_members" not in update["message"]:
                return

            if update["message"]["new_chat_members"] or "left_chat_member" in update["message"]:
                if bot["id"] == Manager.get_main_bot_id():
                    return Foos.status(bot, update)
                return BotsFoos.status(bot, update)

        if infos.user.message.what != "command":
            return Elaborator.reader(infos)

        if infos.user.message.command == "report":
            return Foos.report(infos)

        ok = Elaborator.command_reader(infos)
        if ok != "procedi":
            return

        if infos.user.message.pers_command:
            return Elaborator.pers_commands(infos)

    except Exception as err:
        Log.e("Ho trovato un errore: riga %s %s %s" % (sys.exc_info()[-1].tb_lineno, type(err).__name__, err))
Beispiel #2
0
    def __init__(self, bot, update):
        try:
            self.api = False
            self.time = time.time()

            message, tipe, what = get_message(update)
            self.error = False

            if not message:
                self.skip = True
                return

            self.skip = False
            self.prop_id = Manager.get_prop_id(bot["token"])
            self.what = what
            self.token = bot["token"]
            self.update_id = update["update_id"]
            self.bid = int(bot["id"])
            self.cid = int(message["chat"]["id"])
            tmp = DBs.read_obj(self.bid, self.bid, "users")["ext3"]
            if not tmp:
                self.admins = []
            else:
                self.admins = [int(uid) for uid in tmp.split()]

            self.admins.append(self.prop_id)

            self.entity = self.bid
            self.symbol = Utils.get_com_symbol(self.entity)
            bot["symb"] = self.symbol
            self.bot_name = bot["first_name"]
            self.username = bot["username"]

            if " " in bot["first_name"]:
                self.regex = Utils.regexa(bot["first_name"].lower().split()[0])
            else:
                self.regex = Utils.regexa(bot["first_name"].lower())

            self.regex = Utils.boundary(self.regex)
            self.text = ""
            self.group_username = None
            self.is_reply = False
            self.chat_private = False
            self.error = False
            self.edited = False
            self.admin = False
            self.to_user = None
            self.is_auto = False

            self.is_kitsu = False if Manager.get_main_bot_id(
            ) != self.bid else True

            if "from" in message:
                self.user = User(bot, message["from"], message)
            else:
                if what == "channel_post":
                    name = None
                    if "author_signature" in update["channel_post"]:
                        name = update["channel_post"]["author_signature"]
                    self.user = DummyUser(bot, message, name=name)
                else:
                    self.error = True
                    return

            self.name = message["chat"]["title"] if "title" in message[
                "chat"] else message["chat"]["first_name"]

            self.lang = "ita" if "it" in self.user.lang else "eng"

            self.langn = 0 if "it" in self.user.lang else 1

            if "username" in message["chat"]:
                self.group_username = message["chat"]["username"]

            if "text" in message:
                self.text = message["text"]

            if what != "channel post":
                if "reply_to_message" in message:
                    self.to_user = User(bot,
                                        message["reply_to_message"]["from"],
                                        message["reply_to_message"])
                    self.is_auto = True if self.bid == self.to_user.uid else False
                    self.is_reply = True
                    if self.to_user.uid == self.bid:
                        self.to_user.is_to_bot = True

            if message["chat"]["type"] == 'private':
                self.chat_private = True
                self.admin = True
            else:
                self.perms = Permissions(bot["token"], message["chat"]["id"],
                                         self.bid)
                self.admin = self.perms.is_admin

            self.bot_count = 0

            if tipe:
                self.edited = True
                self.time_diff = int(
                    abs((datetime.strptime(self.user.message.my_time,
                                           "%H:%M:%S") -
                         datetime.strptime(self.user.message.time,
                                           "%H:%M:%S")).seconds))
                self.timed_out = True if self.time_diff > 7 else False

            self.text = self.user.message.text

            self.args = None

            if ": " in self.text:
                tmp_args = self.text.split(": ")
                if len(tmp_args) > 1:
                    self.args = self.text.split(": ")[1]

        except Exception as err:
            Log.w("Qualcosa è andato storto: %s" % err)
            # pprint.pprint(update)
            self.error = True