示例#1
0
def LoadFlags():
    EmptyDictOfFlags = {}
    ListsCache.SetDictOfFlags(GetDictOfFlags())
    DictOfFlags = ListsCache.GetDictOfFlags()
    for i in DictOfFlags:
        EmptyDictOfFlags[i] = ""
    ListsCache.SetEmptyDictOfFlags(EmptyDictOfFlags)
示例#2
0
def CurrenciesSetupMarkup(chatID: str, chatType: str,
                          letter: str) -> InlineKeyboardMarkup:
    lang = DBH.GetSetting(chatID, "lang", chatType)
    dictLang = ButtonTexts[lang]
    AllCurrencies = ListsCache.GetListOfCur()
    TurnedOnCurrencies = DBH.GetAllCurrencies(chatID)
    AllFlags = ListsCache.GetDictOfFlags()
    CurrenciesSetupMU = InlineKeyboardMarkup()
    if len(letter) == 1:
        letter = letter.upper()
        for i in AllCurrencies:
            if i[0] == letter:
                if i in TurnedOnCurrencies:
                    CurrenciesSetupMU.add(
                        InlineKeyboardButton(AllFlags[i] + i + " ✅",
                                             callback_data="cur_" + i))
                else:
                    CurrenciesSetupMU.add(
                        InlineKeyboardButton(AllFlags[i] + i + " ❌",
                                             callback_data="cur_" + i))
    else:
        firstLetter = ord(letter[0].upper())
        lastLetter = ord(letter[1].upper())
        listOfLetters = []
        while firstLetter <= lastLetter:
            listOfLetters.append(chr(firstLetter))
            firstLetter += 1
        for i in AllCurrencies:
            if i[0] in listOfLetters:
                if i in TurnedOnCurrencies:
                    CurrenciesSetupMU.add(
                        InlineKeyboardButton(AllFlags[i] + i + " ✅",
                                             callback_data="cur_" + i))
                else:
                    CurrenciesSetupMU.add(
                        InlineKeyboardButton(AllFlags[i] + i + " ❌",
                                             callback_data="cur_" + i))
    CurrenciesSetupMU.add(
        InlineKeyboardButton(dictLang['back'], callback_data="cur_curmenu"))
    return CurrenciesSetupMU
示例#3
0
def CryptoMenuMarkup(chatID: str, chatType: str) -> InlineKeyboardMarkup:
    lang = DBH.GetSetting(chatID, "lang", chatType)
    dictLang = ButtonTexts[lang]
    CryptoMenuMU = InlineKeyboardMarkup()
    AllCrypto = ListsCache.GetListOfCrypto()
    TurnedOnCrypto = DBH.GetAllCrypto(chatID)
    for i in AllCrypto:
        if i in TurnedOnCrypto:
            CryptoMenuMU.add(
                InlineKeyboardButton(i + " ✅", callback_data="cur_" + i))
        else:
            CryptoMenuMU.add(
                InlineKeyboardButton(i + " ❌", callback_data="cur_" + i))
    CryptoMenuMU.add(
        InlineKeyboardButton(dictLang['back'], callback_data="cur_menu"))
    return CryptoMenuMU
示例#4
0
def LoadCrypto():
    ListsCache.SetListOfCrypto(GetListOfCrypto())
示例#5
0
def LoadCurrencies():
    ListsCache.SetListOfCur(GetListOfCurrencies())
示例#6
0
def AnswerText(Arr: list, chatID: str, chatType: str) -> str:
    def TwoZeroesToOne(s: str):
        while s.rfind("00") == len(s) - 2:
            s = s[:-1]
        return s

    DictOfFlagsForChat = {}

    if GetSetting(chatID, "flags", chatType):
        DictOfFlagsForChat = ListsCache.GetDictOfFlags()
    else:
        DictOfFlagsForChat = ListsCache.GetEmptyDictOfFlags()

    isCryptoLink = False

    answer = ''
    for i in range(len(
            Arr[1])):  #Проходимся по всем распознаным классическим валютам

        answer += "\n" + "======" + "\n"
        CurVault = float(Arr[0][i])
        CurCurrency = ListsCache.GetListOfCur()[Arr[1][i]]
        PartOfAnswer = DictOfFlagsForChat[CurCurrency] + str(
            f'{CurVault:,.2f}'.replace(",", " ")) + " " + CurCurrency + "\n"

        ListOfChatCurrencies = GetAllCurrencies(chatID)
        ListOfChatCrypto = GetAllCrypto(chatID)
        for j in ListOfChatCurrencies:  #Проходимся по всем классическим валютам
            if CurCurrency == j:
                pass
            elif j == 'EUR':
                Vault = round(
                    CurVault / GetExchangeRates.exchangeRates[CurCurrency], 2)
                Vault = f'{Vault:,.2f}'.replace(",", " ")
                PartOfAnswer += "\n" + DictOfFlagsForChat[j] + str(
                    Vault) + " " + j
            elif j != 'EUR':
                Vault = round(
                    CurVault * (GetExchangeRates.exchangeRates[j] /
                                GetExchangeRates.exchangeRates[CurCurrency]),
                    2)
                Vault = f'{Vault:,.2f}'.replace(",", " ")
                PartOfAnswer += "\n" + DictOfFlagsForChat[j] + str(
                    Vault) + " " + j
        if CurCurrency == 'UAH' and CurVault == 40.0:
            PartOfAnswer += "\n👖1 штаны"
        elif CurCurrency == 'USD' and CurVault == 300.0:
            PartOfAnswer += "\n🤛1"

        if len(ListOfChatCurrencies) != 0:
            PartOfAnswer += "\n"

        for j in ListOfChatCrypto:  #Проходимся по всем криптовалютам
            isCryptoLink = True
            if CurCurrency == 'EUR':
                Vault = round(
                    CurVault / GetExchangeRates.exchangeRates[CurCurrency] /
                    GetExchangeRates.cryptoRates[j], 9)
                Vault = f'{Vault:,.9f}'.replace(",", " ")
                PartOfAnswer += "\n" + TwoZeroesToOne(str(Vault)) + " " + j
            elif CurCurrency != 'EUR':
                Vault = round(
                    CurVault * (GetExchangeRates.exchangeRates['USD'] /
                                GetExchangeRates.exchangeRates[CurCurrency] /
                                GetExchangeRates.cryptoRates[j]), 9)
                Vault = f'{Vault:,.9f}'.replace(",", " ")
                PartOfAnswer += "\n" + TwoZeroesToOne(str(Vault)) + " " + j
        answer += PartOfAnswer + "\n"

    for i in range(len(Arr[3])):  #Проходимся по всем распознаным криптовалютам
        isCryptoLink = True
        answer += "\n" + "======" + "\n"
        CurVault = float(Arr[2][i])
        CurCurrency = ListsCache.GetListOfCrypto()[Arr[3][i]]
        PartOfAnswer = TwoZeroesToOne(str(f'{CurVault:,.9f}'.replace(
            ",", " "))) + " " + CurCurrency + "\n"

        ListOfChatCurrencies = GetAllCurrencies(chatID)
        ListOfChatCrypto = GetAllCrypto(chatID)
        for j in ListOfChatCurrencies:  #Проходимся по всем классическим валютам
            if j == 'EUR':
                Vault = round(
                    CurVault * 1 / GetExchangeRates.exchangeRates['USD'] *
                    GetExchangeRates.cryptoRates[CurCurrency], 2)
                Vault = f'{Vault:,.2f}'.replace(",", " ")
                PartOfAnswer += "\n" + DictOfFlagsForChat[j] + str(
                    Vault) + " " + j
            elif j != 'EUR':
                Vault = round(
                    CurVault * GetExchangeRates.exchangeRates[j] /
                    GetExchangeRates.exchangeRates['USD'] *
                    GetExchangeRates.cryptoRates[CurCurrency], 2)
                Vault = f'{Vault:,.2f}'.replace(",", " ")
                PartOfAnswer += "\n" + DictOfFlagsForChat[j] + str(
                    Vault) + " " + j

        if len(ListOfChatCurrencies) != 0:
            PartOfAnswer += "\n"

        for j in ListOfChatCrypto:  #Проходимся по всем криптовалютам
            if CurCurrency == j:
                pass
            else:
                Vault = round(
                    CurVault * GetExchangeRates.cryptoRates[CurCurrency] /
                    GetExchangeRates.cryptoRates[j], 9)
                Vault = f'{Vault:,.9f}'.replace(",", " ")
                PartOfAnswer += "\n" + TwoZeroesToOne(str(Vault)) + " " + j
        answer += PartOfAnswer + "\n"

    if isCryptoLink:
        answer += "\n" + GetText(
            chatID, 'Crypto', chatType
        ) + '<a href="https://accounts.binance.com/en/register?ref=GGMQ44GG">Binance</a>.'

    return answer
示例#7
0
async def CallbackAnswer(call: types.CallbackQuery):
    fromUserId = call.from_user.id
    chatID = call.message.chat.id
    chatType = call.message.chat.type
    callData = call.data
    allAdmins = call.message.chat.all_members_are_administrators
    userName = call.from_user.username

    if IsUserInBlackList(call.message.from_user.id, chatID):
        return
    if callData == "delete":
        CanUserDeleteMes = False
        if chatType == "private":
            CanUserDeleteMes = True
        else:
            whoCanDeleteMes = DBH.GetSetting(chatID, "deleteRules", chatType)
            if whoCanDeleteMes == "everybody":
                CanUserDeleteMes = True
            elif chatType == "group":
                member = await call.message.chat.get_member(fromUserId)
                if allAdmins == True and whoCanDeleteMes == 'admins':
                    CanUserDeleteMes = True
                elif allAdmins == True and whoCanDeleteMes == 'creator':
                    if member.status == 'creator':
                        CanUserDeleteMes = True
                elif allAdmins == False:
                    if whoCanDeleteMes == 'admins' and (
                            member.status == "administrator"
                            or member.status == "creator"
                    ) or whoCanDeleteMes == 'creator' and member.status == "creator":
                        CanUserDeleteMes = True
            elif chatType == "supergroup":
                member = await call.message.chat.get_member(fromUserId)
                if whoCanDeleteMes == 'admins' and (
                        member.status == "administrator"
                        or member.status == "creator"
                ) or whoCanDeleteMes == 'creator' and member.status == "creator":
                    CanUserDeleteMes = True
        if CanUserDeleteMes:
            try:
                await bot.edit_message_text(
                    call.message.text + "\n\n@" +
                    str(call.from_user.username) + " (id: " + str(fromUserId) +
                    ")" + " delete it.", chatID, call.message.message_id)
                await call.message.delete()
            except:
                Print("Cannot delete message.", "E")
    elif str(callData).find("delbut_") == 0:
        member = await call.message.chat.get_member(fromUserId)
        if not CanUserEditSettings(chatID, chatType, member.status,
                                   call.from_user.id, userName, allAdmins):
            return
        Index = str(callData).find("_") + 1
        Value = str(callData)[Index:len(str(callData))]
        if Value == "menu":
            pass
        elif Value == "button":
            IsFlag = DBH.GetSetting(chatID, 'deleteButton', chatType)
            DBH.SetSetting(chatID, 'deleteButton', int(not IsFlag), chatType)
        else:
            DBH.SetSetting(chatID, 'deleteRules', Value, chatType)
        await bot.edit_message_text(
            GetText(chatID, 'delete_button_menu', chatType),
            chatID,
            call.message.message_id,
            reply_markup=CustomMarkup.DeleteButtonMenuMarkup(chatID, chatType))

    elif str(callData).find("lang_") == 0:
        member = await call.message.chat.get_member(fromUserId)
        if not CanUserEditSettings(chatID, chatType, member.status,
                                   call.from_user.id, userName, allAdmins):
            return
        Index = str(callData).find("_") + 1
        Value = str(callData)[Index:len(str(callData))]
        if Value == "menu":
            pass
        else:
            DBH.SetSetting(chatID, 'lang', Value, chatType)
        await bot.edit_message_text(
            GetText(chatID, 'lang_menu', chatType),
            chatID,
            call.message.message_id,
            reply_markup=CustomMarkup.LanguageMenuMarkup(chatID, chatType))

    elif str(callData).find("flags_") == 0:
        member = await call.message.chat.get_member(fromUserId)
        if not CanUserEditSettings(chatID, chatType, member.status,
                                   call.from_user.id, userName, allAdmins):
            return
        Index = str(callData).find("_") + 1
        Value = str(callData)[Index:len(str(callData))]
        if Value == "menu":
            pass
        elif Value == "button":
            IsFlag = DBH.GetSetting(chatID, 'flags', chatType)
            DBH.SetSetting(chatID, 'flags', int(not IsFlag), chatType)
        await bot.edit_message_text(GetText(chatID, 'flags_menu', chatType),
                                    chatID,
                                    call.message.message_id,
                                    reply_markup=CustomMarkup.FlagsMarkup(
                                        chatID, chatType))

    elif str(callData).find("edit_") == 0:
        member = await call.message.chat.get_member(fromUserId)
        memberStatus = member.status
        if not CanUserEditSettings(chatID, chatType, memberStatus,
                                   call.from_user.id, userName, allAdmins):
            return
        Index = str(callData).find("_") + 1
        Value = str(callData)[Index:len(str(callData))]
        if Value == "menu":
            pass
        else:
            if memberStatus == "member":
                pass
            elif memberStatus == "administrator" and (Value == "admins"
                                                      or Value == "everybody"):
                DBH.SetSetting(chatID, 'editSettings', Value, chatType)
            elif memberStatus == "creator":
                DBH.SetSetting(chatID, 'editSettings', Value, chatType)
        await bot.edit_message_text(GetText(chatID, 'edit_menu', chatType),
                                    chatID,
                                    call.message.message_id,
                                    reply_markup=CustomMarkup.EditMenuMarkup(
                                        chatID, chatType))

    elif str(callData).find("cur_") == 0:
        member = await call.message.chat.get_member(fromUserId)
        memberStatus = member.status
        if not CanUserEditSettings(chatID, chatType, memberStatus,
                                   call.from_user.id, userName, allAdmins):
            return
        Index = str(callData).find("_") + 1
        Value = str(callData)[Index:len(str(callData))]

        if Value == "menu":
            await bot.edit_message_text(
                GetText(chatID, "currencies_mainmenu", chatType),
                chatID,
                call.message.message_id,
                reply_markup=CustomMarkup.CurrenciesMainMenuMarkup(
                    chatID, chatType))
        elif Value == "cryptomenu":
            await bot.edit_message_text(
                GetText(chatID, "crypto_mainmenu", chatType),
                chatID,
                call.message.message_id,
                reply_markup=CustomMarkup.CryptoMenuMarkup(chatID, chatType))
        elif Value == "curmenu":
            await bot.edit_message_text(
                GetText(chatID, "currencies_menu", chatType),
                chatID,
                call.message.message_id,
                reply_markup=CustomMarkup.CurrenciesMenuMarkup(
                    chatID, chatType))
        elif len(Value) == 1 or len(Value) == 2:
            await bot.edit_message_text(
                GetText(chatID, "letter_menu", chatType),
                chatID,
                call.message.message_id,
                reply_markup=CustomMarkup.CurrenciesSetupMarkup(
                    chatID, chatType, Value))
        elif len(Value) == 3 or len(Value) == 4:
            DBH.ReverseCurrencySetting(chatID, Value)
            if Value in ListsCache.GetListOfCrypto():
                await bot.edit_message_text(
                    GetText(chatID, "crypto_mainmenu", chatType),
                    chatID,
                    call.message.message_id,
                    reply_markup=CustomMarkup.CryptoMenuMarkup(
                        chatID, chatType))
            else:
                dictForMU = {
                    'A': 'a',
                    'B': 'b',
                    'C': 'c',
                    'D': 'df',
                    'E': 'df',
                    'F': 'df',
                    'G': 'gh',
                    'H': 'gh',
                    'I': 'ij',
                    'J': 'ij',
                    'K': 'kl',
                    'L': 'kl',
                    'M': 'm',
                    'N': 'nq',
                    'O': 'nq',
                    'P': 'nq',
                    'Q': 'nq',
                    'R': 'rs',
                    'S': 'rs',
                    'T': 'tu',
                    'U': 'tu',
                    'V': 'vz',
                    'W': 'vz',
                    'X': 'vz',
                    'Y': 'vz',
                    'Z': 'vz'
                }
                await bot.edit_message_text(
                    GetText(chatID, "letter_menu", chatType),
                    chatID,
                    call.message.message_id,
                    reply_markup=CustomMarkup.CurrenciesSetupMarkup(
                        chatID, chatType, dictForMU[Value[0]]))

    elif callData == "settings":
        await bot.edit_message_text(GetText(chatID, "main_settings_menu",
                                            chatType),
                                    chatID,
                                    call.message.message_id,
                                    reply_markup=CustomMarkup.SettingsMarkup(
                                        chatID, chatType))
示例#8
0
async def MainVoid(message: types.Message):
    fromUserId = message.from_user.id
    chatID = message.chat.id
    chatType = message.chat.type

    def w2n(MesString: str, lang: str):
        if lang == "ua":
            return numberizerUA.replace_numerals(MesString)
        elif lang == "ru":
            return numberizerRU.replace_numerals(MesString)
        else:
            return numberizerEN.replace_numerals(MesString)

    try:
        if message.forward_from.username == botUsername:
            return
    except:
        pass

    # Checking if a user is on the blacklist
    if IsUserInBlackList(fromUserId, chatID):
        return

    # Get message text
    MessageText = message.text
    if message.photo or message.video is not None or message.document is not None:
        MessageText = message.caption
    if MessageText is None or MessageText == "":
        return

    # Logging basic information to terminal
    PrintMainInfo(message, MessageText)

    # Checking the chat in the database
    IsChatExist(chatID, chatType)

    # word to num
    OriginalMessageText = MessageText
    MessageText = MessageText.lower()
    MessageText = RemoveLinksAndWords(MessageText)
    MessageText = w2n(MessageText, 'ru')
    MessageText = w2n(MessageText, 'uk')
    MessageText = w2n(MessageText, 'en')
    Print(MessageText, "L")

    # Check digit
    if not any(map(str.isdigit, MessageText)):
        return

    # Preparing a message for searching currencies
    try:
        TextArray = SpecialSplit(MessageText)
    except:
        Print("Error split.", "E")
        return
    Print(str(TextArray), "L")

    # '5kk USD' to '5000000 USD'
    TextArray = TextToDigit(TextArray)
    Print(str(TextArray), "L")

    # Searching Currencies
    NumArray = SearchValuesAndCurrencies(TextArray)
    Print(str(NumArray), "L")

    # If there are no currencies, then work is interrupted
    if NumArray == [[], [], [], []]:
        return

    if StopDDoS.updateData(fromUserId, chatID,
                           len(NumArray[1]) + len(NumArray[3]),
                           message.chat.title):
        await message.reply(GetText(chatID, 'added_to_bl', chatType))
        ListAdmins = DBH.GetAdmins()
        for i in ListAdmins:
            await bot.send_message(
                i,
                "Пользователь " + str(fromUserId) +
                " заблокирован. Его возможное имя пользователя: @" +
                str(message.from_user.username),
                reply_markup=CustomMarkup.DeleteMarkup(i, "private"))
        return

    result = AnswerText(NumArray, chatID, chatType)
    try:
        await message.reply(result,
                            parse_mode="HTML",
                            reply_markup=CustomMarkup.DeleteMarkup(
                                chatID, chatType))
    except:
        Print("Cannot send message", "E")
        Print(
            "Username: "******" | User ID: " +
            str(message.from_user.id) + " | First name: " +
            str(message.from_user.first_name) + " | Last name: " +
            str(message.from_user.last_name), "E")
        Print(
            "Chat ID: " + str(message.chat.id) + " | Chat name: " +
            str(message.chat.title) + " | Chat username: "******" | Chat type: " +
            str(message.chat.type), "E")
        Print("Message: " + str(OriginalMessageText), "E")
    DBH.UpdateChatUsage(chatID)
    for i in NumArray[1]:
        DBH.ProcessedCurrency(chatID, fromUserId,
                              ListsCache.GetListOfCur()[i],
                              OriginalMessageText)
    for i in NumArray[3]:
        DBH.ProcessedCurrency(chatID, fromUserId,
                              ListsCache.GetListOfCrypto()[i],
                              OriginalMessageText)