コード例 #1
0
def init(update, context):
    languages(update, context)
    reply = update.message.reply_to_message
    if reply is not None:
        delete_message_reply(update, context)
    else:
        message(update, context, languages.delete_error_msg)
コード例 #2
0
ファイル: ban.py プロジェクト: mdnmdn/nebula8
def ban_success(update, context, chat, username=None, id=None):
    languages(update, context)
    message(update, context,
            languages.user_ban % (username if username is not None else id))
    logs_text = "<b>#Log User Banned!</b>\nGroup: {}\nUser: {}".format(
        chat.id, username or id)
    telegram_loggers(update, context, logs_text)
コード例 #3
0
def init(update,context):
    text = update.message.text
    if update.message.reply_to_message:
        user = user_reply_object(update)
        row = UserRepository().getById(user.id)
        if row:
            message(update, context, text="<b>The user search returned the following results:</b>\nTelegram Id: <code>{}</code>\nUsername: {}\nLast Update: {}"
            .format(
                row['tg_id'],
                row['tg_username'],
                row['updated_at'].isoformat()
                ))
        else:
            message(update,context, text="The user is not present in the database")
    else:
        input_user_id = text[8:].strip().split(" ", 1)
        user_id = input_user_id[0]
        if user_id != "":
            row = UserRepository().getByUsername(user_id)
            if row:
                message(update, context, text="<b>The user search returned the following results:</b>\nTelegram Id: <code>{}</code>\nUsername: {}\nLast Update: {}"
                .format(
                    row['tg_id'],
                    row['tg_username'],
                    row['updated_at'].isoformat()
                    ))
            else:
                message(update,context, text="The user is not present in the database")
        else:
            message(update,context,"Attention the user id you entered does not exist!")
コード例 #4
0
def init(update, context):
    languages(update, context)
    msg = update.message.text[4:].strip()
    if msg != "":
        message(update, context, msg)
    else:
        message(update, context, languages.say_error)
コード例 #5
0
ファイル: source.py プロジェクト: mdnmdn/nebula8
def init(update, context):
    bot = bot_object(update, context)
    version = Config.VERSION
    version_name = Config.VERSION_NAME
    repo = Config.REPO
    format_message = Strings.SOURCE.format("@" + bot.username, version,
                                           version_name, repo)
    message(update, context, format_message)
コード例 #6
0
ファイル: badword.py プロジェクト: Squirrel-Network/nebula8
def init(update, context):
    chat = chat_object(update)
    msg = update.message.text[8:].strip()
    if msg != "":
        data = [(msg, chat.id)]
        GroupRepository().insert_badword(data)
        message(update, context, languages.badlist_add.format(msg))
    else:
        message(update, context, languages.badlist_add_empty)
コード例 #7
0
ファイル: distrowatch.py プロジェクト: mdnmdn/nebula8
def init(update, context):
    r = requests.get("https://distrowatch.com/random.php")
    parsed_html = BeautifulSoup(r.text, features="html.parser")
    distro_long_name = parsed_html.title.string[17:].lower()
    distro_name = distro_long_name.split()[0]
    distro_url = f'https://distrowatch.com/table.php?distribution={distro_name}'
    distro_message = "Here is a random linux distribution: {}".format(
        distro_url)
    message(update, context, distro_message)
コード例 #8
0
ファイル: info_group.py プロジェクト: tanya4067/nebula8
def init(update, context):
    languages(update, context)
    chat = update.effective_message.chat_id
    rows = GroupRepository().getById([chat])
    for row in rows:
        message(
            update, context,
            languages.group_info.format(row['id_group'], row['welcome_text'],
                                        row['rules_text'], row['languages']))
コード例 #9
0
ファイル: migrate_chat.py プロジェクト: mdnmdn/nebula8
def init(update, context):
    if update.effective_message.migrate_from_chat_id is not None:
        old_chat_id = update.message.migrate_from_chat_id
        new_chat_id = update.message.chat.id
        data = [(new_chat_id, old_chat_id)]
        GroupRepository().update(data)
        message(
            update, context,
            "<b>#Automatic handler:</b>\nThe chat has been migrated to <b>supergroup</b> the bot has made the modification on the database.\n<i>It is necessary to put the bot admin</i>"
        )
コード例 #10
0
ファイル: set_welcome.py プロジェクト: mdnmdn/nebula8
def init(update, context):
    languages(update,context)
    chat = update.effective_chat.id
    msg = update.message.text[8:].strip()
    if msg != "":
        data = [(msg, chat)]
        GroupRepository().update_group_welcome(data)
        message(update, context, languages.set_welcome_help)
    else:
        message(update, context, languages.set_welcome_main)
コード例 #11
0
def init(update, context):
    bot = context.bot
    chat = chat_object(update)
    link = bot.export_chat_invite_link(chat.id)
    message(
        update, context,
        "An invitation link was generated for the chat <b>{}</b>\nThe invitation was sent in <i>private</i>"
        .format(chat.title))
    PrivateMessage(update, context,
                   "Chat: {}\nInvite Link: {}".format(chat.title, link))
コード例 #12
0
def init(update, context):
    record = GroupRepository.SET_RULES_TEXT
    chat = update.effective_chat.id
    msg = update.message.text[9:].strip()
    languages(update, context)
    if msg != "":
        data = [(msg, chat)]
        GroupRepository().update_group_settings(record, data)
        message(update, context, languages.rules_msg)
    else:
        message(update, context, languages.rules_error_msg)
コード例 #13
0
def init(update, context):
    user = user_object(update)
    nickname = "@" + user.username
    superban = SuperbanRepository().getById(user.id)
    if superban:
        msg = "<b>User id:</b> <code>{}</code>\n<b>Nickname:</b> {}\n<b>Blacklist:</b> ✅".format(
            user.id, nickname or user.first_name)
    else:
        msg = "<b>User id:</b> <code>{}</code>\n<b>Nickname:</b> {}\n<b>Blacklist:</b> ❌".format(
            user.id, nickname or user.first_name)
    message(update, context, msg)
コード例 #14
0
ファイル: add_community.py プロジェクト: mdnmdn/nebula8
def init(update, context):
    chat = chat_object(update)
    link = "https://t.me/{}".format(chat.username)
    row = CommunityRepository().getById(chat.id)
    if row:
        data = [(chat.title, chat.id)]
        CommunityRepository().update(data)
        message(update, context, "Update Community")
    else:
        data = [(chat.title, chat.id, link)]
        CommunityRepository().add(data)
        message(update, context, "Insert Community")
コード例 #15
0
def init(update, context):
    msg = update.message.text[2:].strip()
    rows = CommunityRepository().getAll()
    for a in rows:
        id_groups = a['tg_group_id']
        try:
            if msg != "":
                messageWithId(update, context, id_groups, msg)
            else:
                message(update, context, "You cannot send an empty message!")
        except BadRequest:
            message(update, context, Strings.ERROR_HANDLING)
コード例 #16
0
def multi_superban(update, context):
    txt = update.message.text
    x = re.findall(r'\d+', txt)
    string = "MultiSuperban eseguito! dei seguenti id:\n"
    for a in x:
        save_date = datetime.datetime.utcnow().isoformat()
        default_motivation = "MultiSuperban"
        operator_id = update.message.from_user.id
        data = [(a, default_motivation, save_date, operator_id)]
        SuperbanRepository().add(data)
        string += "▪️ {}\n".format(a)
    message(update, context, string)
コード例 #17
0
ファイル: badword.py プロジェクト: Squirrel-Network/nebula8
def badlist(update, context):
    chat = chat_object(update)
    languages(update, context)
    rows = GroupRepository().get_badwords_group(chat.id)
    if rows:
        string = ""
        for row in rows:
            string += "▪️ {}\n".format(row['word'])
        message(update, context,
                languages.badlist_text.format(chat.title, string))
    else:
        message(update, context, languages.badlist_empty)
コード例 #18
0
ファイル: start.py プロジェクト: Squirrel-Network/nebula8
def init(update, context):
    languages(update,context)
    bot = bot_object(update,context)
    user = user_object(update)
    get_user_lang = user.language_code
    if get_user_lang == 'it':
        message(update,context,
        "Ciao io mi chiamo {} e sono uno strumento per la gestione dei gruppi con tante funzioni speciali"\
            " tutte da scoprire! e sono Open Source! Se vuoi vedere il mio sorgente digita:"\
            " /source\nSe hai bisogno di aiuto digita /help".format("@"+bot.username))
    else:
        message(update,context,languages.start.format("@"+bot.username))
コード例 #19
0
def global_broadcast(update, context):
    msg = update.message.text[3:].strip()
    rows = GroupRepository().getAll()
    for a in rows:
        id_groups = a['id_group']
        try:
            if msg != "":
                loop.run_until_complete(
                    messageWithAsyncById(update, context, id_groups, 2, msg))
            else:
                message(update, context, "You cannot send an empty message!")
        except (BadRequest, Unauthorized):
            message(update, context, Strings.ERROR_HANDLING)
コード例 #20
0
ファイル: report.py プロジェクト: Squirrel-Network/nebula8
def global_report(update, context):
    bot = context.bot
    chat = chat_object(update)
    languages(update, context)
    if update.effective_message.reply_to_message:
        message(update, context, languages.delete_error_msg)
    else:
        link = bot.export_chat_invite_link(chat.id)
        msg = "#GlobalReport\nChatId: {}\nChat: {}\nLink: {}".format(
            chat.id, chat.title, link)
        msg_report = languages.global_report_msg
        staff_loggers(update, context, msg)
        message(update, context, msg_report)
コード例 #21
0
def convert_time(update, context, time_args):
    if time_args == "1d":
        time_args = int(86400)
    elif time_args == "3d":
        time_args = int(259200)
    elif time_args == "7d":
        time_args = int(604800)
    elif time_args == "1h":
        time_args = int(3600)
    elif time_args == "30s":
        time_args = int(30)
    else:
        error_msg = "You must enter a valid time value for the bot among the following: <code>1d, 3d, 7d, 1h, 30s</code>"
        message(update, context, error_msg)
    return int(time_args)
コード例 #22
0
ファイル: wikipedia.py プロジェクト: mdnmdn/nebula8
def init(update, context):
    arg = update.message.text[5:]
    chat = update.effective_message.chat_id
    group = GroupRepository().getById(chat)
    lang = group['languages']
    wiki.set_lang(lang.lower())
    try:
        pg = wiki.page(wiki.search(arg)[0])
        title = pg.title
        pg_url = pg.url
        define = pg.summary
        button_list = [InlineKeyboardButton("Go to ==>", url=pg_url)]
        reply_markup = InlineKeyboardMarkup(build_menu(button_list, n_cols=1))
        text = "*{}:*\n\n{}".format(title, define)
        update.message.reply_markdown(text, reply_markup=reply_markup)
    except:
        message(update, context, "Sorry {} I didn't find what you were looking for".format(update.message.from_user.first_name))
コード例 #23
0
def init(update, context):
    bot = bot_object(update, context)
    chat_id = update.message.chat_id
    get_bot = bot.getChatMember(chat_id, bot.id)
    languages(update, context)

    perm_delete = get_bot.can_delete_messages
    perm_ban = get_bot.can_restrict_members
    perm_pin = get_bot.can_pin_messages
    perm_edit_msg = get_bot.can_be_edited
    perm_media = get_bot.can_send_media_messages
    perm_send_message = get_bot.can_send_messages
    if None in [
            perm_delete, perm_ban, perm_pin, perm_edit_msg, perm_media,
            perm_send_message
    ]:
        message(update, context, languages.perm_error)
    else:
        message(update, context, languages.perm_ok)
コード例 #24
0
ファイル: search.py プロジェクト: Squirrel-Network/nebula8
def duckduckgo(update, context):
    bot = context.bot
    msg = str(update.message.text[4:]).strip()
    if msg != "":
        main_text = "Here are the results of your DuckDuckGo search"
        gurl = "https://duckduckgo.com/?q={0}".format(msg.replace(' ', '+'))
        button_list = [InlineKeyboardButton("🔎 Search", url=gurl)]
        reply_markup = InlineKeyboardMarkup(build_menu(button_list, n_cols=1))
        bot.send_message(update.message.chat_id,
                         text=main_text,
                         reply_markup=reply_markup,
                         parse_mode='HTML')
    else:
        message(
            update,
            context,
            text=
            "You need to type a search criteria!\nHow to use the command: <code>/ddg text</code>"
        )
コード例 #25
0
def init(update, context):
    languages(update, context)
    if update.message.reply_to_message:
        user = update.message.reply_to_message.from_user
        buttons = []
        buttons.append(
            InlineKeyboardButton(languages.mute_button,
                                 callback_data='CMunmute'))
        buttons.append(InlineKeyboardButton('30Sec', callback_data='CM30'))
        buttons.append(InlineKeyboardButton('1 Hour', callback_data='CM3600'))
        buttons.append(InlineKeyboardButton('1 Day', callback_data='CM86400'))
        buttons.append(InlineKeyboardButton('3 Days',
                                            callback_data='CM259200'))
        buttons.append(InlineKeyboardButton('7 Days',
                                            callback_data='CM604800'))
        buttons.append(
            InlineKeyboardButton('Forever', callback_data='CMforever'))
        menu = build_menu(buttons, 2)
        msg = languages.mute_msg.format(user.id, user.first_name, user.id)
        update.message.reply_to_message.reply_text(
            msg, reply_markup=InlineKeyboardMarkup(menu), parse_mode='HTML')
        mute_user_reply(update, context, True)
    else:
        text = update.message.text
        input_user_id = text[5:].strip().split(" ", 1)
        user_id = input_user_id[0]
        time_args = input_user_id[1]
        if user_id != "" and time_args != "":
            if user_id.startswith('@'):
                time_args = input_user_id[1]
                arg_time = convert_time(update, context, time_args)
                mute_user_by_username_time(update, context, user_id, arg_time)
                msg = 'You muted the user {} for <code>{}</code> seconds'.format(
                    user_id, time_args)
                message(update, context, msg)
            else:
                time_args = input_user_id[1]
                number = re.search(Regex.HAS_NUMBER, user_id)
                if number is None:
                    message(
                        update, context,
                        "Type a correct telegram id or type in the username!")
                else:
                    mute_user_by_id_time(update, context, user_id, True,
                                         int(time_args))
                    msg = 'You muted the user <a href="tg://user?id={}">{}</a> <code>[{}]</code> for <code>{}</code> seconds'.format(
                        user_id, user_id, user_id, time_args)
                    message(update, context, msg)
        else:
            message(
                update, context,
                "Attention you have not entered the user id and mute time correctly"
            )
コード例 #26
0
def init(update, context):
    bot = context.bot
    msg = str(update.message.text[7:]).strip()
    if msg != "":
        main_text = "Here are the results of your Google search"
        gurl = "https://www.google.com/search?&q={0}".format(
            msg.replace(' ', '+'))
        button_list = [InlineKeyboardButton("Go to =>", url=gurl)]
        reply_markup = InlineKeyboardMarkup(build_menu(button_list, n_cols=1))
        bot.send_message(update.message.chat_id,
                         text=main_text,
                         reply_markup=reply_markup,
                         parse_mode='HTML')
    else:
        message(
            update,
            context,
            text=
            "You need to type a search criteria!\nHow to use the command: <code>/google text</code>"
        )
コード例 #27
0
ファイル: whitelist.py プロジェクト: Squirrel-Network/nebula8
def init(update, context):
    if update.message.reply_to_message:
        user = user_reply_object(update)
        row = SuperbanRepository().getWhitelistById(user.id)
        get_superban = SuperbanRepository().getById(user.id)
        if get_superban:
            buttons = []
            buttons.append(
                InlineKeyboardButton('Remove Superban',
                                     callback_data='removeBL'))
            buttons.append(
                InlineKeyboardButton('Close', callback_data='closed'))
            menu = build_menu(buttons, 2)
            msg = "Attention the user is blacklisted! do you want to remove it?"
            update.message.reply_to_message.reply_text(
                msg,
                reply_markup=InlineKeyboardMarkup(menu),
                parse_mode='HTML')
        else:
            if row:
                message(update, context,
                        "You have already whitelisted this user")
            else:
                user_username = "******" + user.username
                data = [(user.id, user_username)]
                SuperbanRepository().addWhitelist(data)
                message(
                    update, context,
                    "You have entered the user {} in the Whitelist".format(
                        user_username))
    else:
        message(update, context,
                "This message can only be used in response to a user")
コード例 #28
0
ファイル: warn.py プロジェクト: Squirrel-Network/nebula8
def init(update,context):
    chat = chat_object(update)
    get_group = GroupRepository().getById(chat.id)
    max_warn = get_group['max_warn']
    current_time = datetime.datetime.utcnow().isoformat()
    default_warn = 1
    languages(update,context)
    if update.message.reply_to_message:
        reason = update.message.text[5:]
        user = user_reply_object(update)
        get_user = UserRepository().getUserByGroup([user.id,chat.id])
        warn_count = get_user['warn_count'] if get_user is not None else 0
        if warn_count != max_warn:
            buttons = []
            buttons.append(InlineKeyboardButton('➖ 1', callback_data='downWarn'))
            buttons.append(InlineKeyboardButton('➕ 1', callback_data='upWarn'))
            buttons.append(InlineKeyboardButton(languages.button_remove, callback_data='removeWarn'))
            menu = build_menu(buttons,3)
            if get_user:
                default_warn_count = 0
                username = "******"+user.username
                data = [(username,current_time,user.id)]
                UserRepository().update(data)
                data_mtm = [(user.id, chat.id, default_warn_count)]
                UserRepository().add_into_mtm(data_mtm)
                data_warn = [(user.id,chat.id)]
                UserRepository().updateWarn(data_warn)
                if reason:
                    msg = languages.warn_with_reason.format(mention_html(user.id, user.first_name),chat.title,chat.id,reason)
                    update.message.reply_to_message.reply_text(msg, reply_markup=InlineKeyboardMarkup(menu),parse_mode='HTML')
                else:
                    msg = languages.warn_user.format(mention_html(user.id, user.first_name),chat.title,chat.id)
                    update.message.reply_to_message.reply_text(msg, reply_markup=InlineKeyboardMarkup(menu),parse_mode='HTML')
                log_txt = "‼️ #Log {} was warned\nin the group: {} <code>[{}]</code>".format(mention_html(user.id, user.first_name),chat.title,chat.id)
                if reason:
                    log_txt = "‼️ #Log {} was warned\nin the group: {} <code>[{}]</code>\nReason: {}".format(mention_html(user.id, user.first_name),chat.title,chat.id,reason)
                telegram_loggers(update,context,log_txt)
            else:
                username = "******"+user.username
                data = [(user.id,username,current_time,current_time)]
                UserRepository().add(data)
                data_mtm = [(user.id, chat.id, default_warn)]
                UserRepository().add_into_mtm(data_mtm)
                if reason:
                    message(update,context,languages.warn_with_reason.format(username,chat.title,chat.id,reason))
                else:
                    message(update,context,languages.warn_user.format(username,chat.title,chat.id))
                log_txt = "‼️ #Log {} was warned\nin the group: {} <code>[{}]</code>".format(mention_html(user.id, user.first_name),chat.title,chat.id)
                if reason:
                    log_txt = "‼️ #Log {} was warned\nin the group: {} <code>[{}]</code>\nReason: {}".format(mention_html(user.id, user.first_name),chat.title,chat.id,reason)
                telegram_loggers(update,context,log_txt)
        else:
            ban_user_reply(update,context)
            buttons = []
            buttons.append(InlineKeyboardButton('Remove', callback_data='removeWarn'))
            menu = build_menu(buttons,2)
            msg = languages.warn_user_max.format(user.username,chat.title)
            update.message.reply_to_message.reply_text(msg, reply_markup=InlineKeyboardMarkup(menu),parse_mode='HTML')
    else:
        message(update,context,languages.error_response_user_msg)
コード例 #29
0
def init(update,context):
    bot = context.bot
    chat = chat_object(update)
    if chat.type == 'supergroup':
        row = CommunityRepository().getById(chat.id)
        if row:
            record = GroupRepository.SET_COMMUNITY
            default_community = 1
            data = [(chat.title,chat.id)]
            data_group = [(default_community, chat.id)]
            CommunityRepository().update(data)
            GroupRepository().update_group_settings(record,data_group)
            message(update,context,"I updated the community on the database")
        else:
            buttons = []
            buttons.append(InlineKeyboardButton('IT', callback_data='commIT'))
            buttons.append(InlineKeyboardButton('EN', callback_data='commEN'))
            buttons.append(InlineKeyboardButton('Close', callback_data='closeMenu'))
            menu = build_menu(buttons,2)
            bot.send_message(chat_id=update.effective_chat.id,text="Please select the language of the community",reply_markup=InlineKeyboardMarkup(menu))
    else:
        message(update,context,"Attention! this command can only be used in public supergroups!")
コード例 #30
0
def set_log_channel(update, context):
    msg = update.effective_message
    chat = update.effective_chat
    user = update.effective_user
    record = GroupRepository.SET_LOG_CHANNEL
    if user is not None:
        member = chat.get_member(user.id)
    if chat.type == 'channel' and str(
            update.effective_message.text).lower().startswith("/setlog"):
        msg.reply_text(
            "Now, forward the /setlog to the group you want to tie this channel to!"
        )

    elif msg.forward_from_chat and msg.text == '/setlog' and member.status == 'creator':
        data = [(msg.forward_from_chat.id, chat.id)]
        GroupRepository().update_group_settings(record, data)
        try:
            msg.delete()
        except BadRequest as excp:
            if excp.message == "Message to delete not found":
                pass
            else:
                message(
                    update, context,
                    "Error deleting message in log channel. Should work anyway though."
                )

        try:
            messageWithId(
                update, context, msg.forward_from_chat.id,
                "This channel has been set as the log channel for {}.".format(
                    chat.title or chat.first_name))
        except Unauthorized as excp:
            if excp.message == "Forbidden: bot is not a member of the channel chat":
                message(update, context, "Successfully set log channel!")
            else:
                message(update, context, "ERROR in setting the log channel.")

        message(update, context, "Successfully set log channel!")

    else:
        if str(update.effective_message.text).lower().startswith("/setlog"):
            msg.reply_text("The steps to set a log channel are:\n"
                           " - add bot to the desired channel\n"
                           " - send /setlog to the channel\n"
                           " - forward the /setlog to the group\n"
                           " - You need to be a creator of the group")