Пример #1
0
def main():
    test_handler = CustomCommandHandler(CMD_PREFIX, "test", test)
    start_handler = CustomCommandHandler(CMD_PREFIX, "start", start)

    help_handler = CustomCommandHandler(CMD_PREFIX, "help", get_help)
    help_callback_handler = CallbackQueryHandler(help_button, pattern=r"help_")

    settings_handler = CustomCommandHandler(CMD_PREFIX, "settings",
                                            get_settings)
    settings_callback_handler = CallbackQueryHandler(settings_button,
                                                     pattern=r"stngs_")

    donate_handler = CustomCommandHandler(CMD_PREFIX, "donate", donate)
    migrate_handler = MessageHandler(Filters.status_update.migrate,
                                     migrate_chats)

    # dispatcher.add_handler(test_handler)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(help_handler)
    dispatcher.add_handler(settings_handler)
    dispatcher.add_handler(help_callback_handler)
    dispatcher.add_handler(settings_callback_handler)
    dispatcher.add_handler(migrate_handler)
    dispatcher.add_handler(donate_handler)

    # dispatcher.add_error_handler(error_callback)

    if WEBHOOK:
        LOGGER.info("Using webhooks.")
        updater.start_webhook(listen="0.0.0.0", port=PORT, url_path=TOKEN)

        if CERT_PATH:
            updater.bot.set_webhook(url=URL + TOKEN,
                                    certificate=open(CERT_PATH, 'rb'))
        else:
            updater.bot.set_webhook(url=URL + TOKEN)

    else:
        LOGGER.info("Using long polling.")
        updater.start_polling(timeout=15, read_latency=4)

    updater.idle()
Пример #2
0
            pass


__help__ = """
 - /addrss <link>: add an RSS link to the subscriptions.
 - /removerss <link>: removes the RSS link from the subscriptions.
 - /rss <link>: shows the link's data and the last entry, for testing purposes.
 - /listrss: shows the list of rss feeds that the chat is currently subscribed to.

NOTE: In groups, only admins can add/remove RSS links to the group's subscription
"""

__mod_name__ = "RSS Feed"

job = updater.job_queue

job_rss_set = job.run_once(rss_set, 5)
job_rss_update = job.run_repeating(rss_update, interval=60, first=60)
job_rss_set.enabled = True
job_rss_update.enabled = True

SHOW_URL_HANDLER = CustomCommandHandler(CMD_PREFIX, "rss", show_url)
ADD_URL_HANDLER = CustomCommandHandler(CMD_PREFIX, "addrss", add_url)
REMOVE_URL_HANDLER = CustomCommandHandler(CMD_PREFIX, "removerss", remove_url)
LIST_URLS_HANDLER = CustomCommandHandler(CMD_PREFIX, "listrss", list_urls)

dispatcher.add_handler(SHOW_URL_HANDLER)
dispatcher.add_handler(ADD_URL_HANDLER)
dispatcher.add_handler(REMOVE_URL_HANDLER)
dispatcher.add_handler(LIST_URLS_HANDLER)
Пример #3
0
        changes = json.loads(res.text).get('LightGingerTheTextResult')
        curr_string = ""

        prev_end = 0

        for change in changes:
            start = change.get('From')
            end = change.get('To') + 1
            suggestions = change.get('Suggestions')
            if suggestions:
                sugg_str = suggestions[0].get(
                    'Text')  # should look at this list more
                curr_string += msg.text[prev_end:start] + sugg_str

                prev_end = end

        curr_string += msg.text[prev_end:]
        print(curr_string)
        update.effective_message.reply_text(curr_string)


__help__ = """
 - /t: while replying to a message, will reply with a grammar corrected version
"""

__mod_name__ = "Translator"

TRANSLATE_HANDLER = CustomCommandHandler(CMD_PREFIX, 't', translate)

dispatcher.add_handler(TRANSLATE_HANDLER)
Пример #4
0
 - /clearlink: clear the group link for this chat. (Private supergroups only)
 - /linkmode <code/button/hyperlink/bare>: set your preferred ways to show group link.

 - /promote: promotes the user replied to
 - /demote: demotes the user replied to
 
 An example of set a link:
`/setlink https://t.me/joinchat/HwiIk1RADK5gRMr9FBdOrwtae`

An example of promoting someone to admins:
`/promote @username`; this promotes a user to admins.
""".format(dispatcher.bot.first_name)

__mod_name__ = "Admin"

PIN_HANDLER = CustomCommandHandler(CMD_PREFIX, "pin", pin, filters=Filters.group)
UNPIN_HANDLER = CustomCommandHandler(CMD_PREFIX, "unpin", unpin, filters=Filters.group)
LINK_HANDLER = DisableAbleCommandHandler(CMD_PREFIX, "link", link_public)
SET_LINK_HANDLER = CustomCommandHandler(CMD_PREFIX, "setlink", set_link, filters=Filters.group)
LINKMODE_HANDLER = CustomCommandHandler(CMD_PREFIX, "linkmode", linkmode, filters=Filters.group)
RESET_LINK_HANDLER = CustomCommandHandler(CMD_PREFIX, "clearlink", clear_link, filters=Filters.group)
HASH_LINK_HANDLER = MessageHandler(Filters.regex(r"#link"), link_public)
INVITE_HANDLER = CustomCommandHandler(CMD_PREFIX, "invitelink", invite, filters=Filters.group)
PERMAPIN_HANDLER = CustomCommandHandler(CMD_PREFIX, ["permapin", "perma"], permapin, filters=Filters.group)
PROMOTE_HANDLER = CustomCommandHandler(CMD_PREFIX, "promote", promote, filters=Filters.group)
DEMOTE_HANDLER = CustomCommandHandler(CMD_PREFIX, "demote", demote, filters=Filters.group)
ADMINLIST_HANDLER = DisableAbleCommandHandler(CMD_PREFIX, ["adminlist", "staff"], adminlist, filters=Filters.group)

dispatcher.add_handler(PIN_HANDLER)
dispatcher.add_handler(UNPIN_HANDLER)
dispatcher.add_handler(INVITE_HANDLER)
Пример #5
0
                                               mention_html(user.id, user.first_name))
    else:
        update.effective_message.reply_text("Whadya want to delete?")

    return ""


__help__ = """
Deleting messages made easy with this command. Bot purges \
messages all together or individually.

*Admin only:*
 - /del: deletes the message you replied to
 - /purge: deletes all messages between this and the replied to message.
 - /purge <integer X>: deletes the replied message, and X messages following it.
"""

__mod_name__ = "Purges"

DELETE_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                      "del",
                                      del_message,
                                      filters=Filters.group)
PURGE_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                     "purge",
                                     purge,
                                     filters=Filters.group)

dispatcher.add_handler(DELETE_HANDLER)
dispatcher.add_handler(PURGE_HANDLER)
Пример #6
0
 - /rmwhitelist <domains>: Same as above.


Locks can be used to restrict a group's users.
eg:
Locking urls will auto-delete all messages with urls which haven't been whitelisted, locking stickers will delete all \
stickers, etc.
Locking bots will stop non-admins from adding bots to the chat.
"""

__mod_name__ = "Locks & Whitelists"

LOCKTYPES_HANDLER = DisableAbleCommandHandler(CMD_PREFIX, "locktypes",
                                              locktypes)
LOCK_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                    "lock",
                                    lock,
                                    filters=Filters.group)
UNLOCK_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                      "unlock",
                                      unlock,
                                      filters=Filters.group)
LOCKED_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                      "locks",
                                      list_locks,
                                      filters=Filters.group)

dispatcher.add_handler(LOCK_HANDLER)
dispatcher.add_handler(UNLOCK_HANDLER)
dispatcher.add_handler(LOCKTYPES_HANDLER)
dispatcher.add_handler(LOCKED_HANDLER)
Пример #7
0
`/sban @username or 728762378`; this bans user silently and deletes command.

An example of temporarily mute someone:
`/tmute @username 2h`; this mutes a user for 2 hours.

An example of temporarily restricting someone:
`/trestrict @username 2h`; this restricts a user's ability to send media for 2 hours.

An example of muting someone silently:
`/smute @username or 728762378`; this mutes user silently and deletes command.
""".format(dispatcher.bot.first_name)

__mod_name__ = "Banhammer"

BAN_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                   "ban",
                                   ban,
                                   filters=Filters.group)
TEMPBAN_HANDLER = CustomCommandHandler(CMD_PREFIX, ["tban", "tempban"],
                                       temp_ban,
                                       filters=Filters.group)
KICK_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                    "kick",
                                    kick,
                                    filters=Filters.group)
UNBAN_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                     "unban",
                                     unban,
                                     filters=Filters.group)
KICKME_HANDLER = DisableAbleCommandHandler(CMD_PREFIX,
                                           "kickme",
                                           kickme,
Пример #8
0
left unused; to avoid spam and abuse.

This allows you to disable some commonly used commands, so noone can use them. \
It'll also allow you to auto-delete them, stopping people from blue-texting.

 - /disabled: check the current status of disabled commands

*Admin only:*
 - /disable <commandname>: stop users from using the "commandname" command in this group.
 - /enable <commandname>: allow users to use the "commandname" command in this group again.
 - /disableable: list all disableable commands.
 - /disabledel <on/off/yes/no>: delete disabled commands when used by non-admins.
    """.format(dispatcher.bot.first_name)

    DISABLE_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                           "disable",
                                           disable,
                                           filters=Filters.group)
    ENABLE_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                          "enable",
                                          enable,
                                          filters=Filters.group)
    #    DISABLEDEL_HANDLER = CommandHandler("disabledel", disable_del, pass_args=True, filters=Filters.group)
    COMMANDS_HANDLER = CustomCommandHandler(CMD_PREFIX, ["cmds", "disabled"],
                                            commands,
                                            filters=Filters.group)
    TOGGLE_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                          ["disableable", "listcmds"],
                                          list_cmds,
                                          filters=Filters.group)
    #    DISABLEDEL = MessageHandler(Filters.command & Filters.group, del_cmds)
Пример #9
0
If you wish to add more than 1 buttons simply do the following:
`[Button 1](buttonurl://example.com)`
`[Button 2](buttonurl://github.com:same)`
`[Button 3](buttonurl://google.com)`

The `:same` end of the link merges 2 buttons on same line as 1 button, resulting in 3rd button to be separated \
from same line.

Tip: Buttons must be placed at the end of welcome messages. 
""".format(WELC_HELP_TXT)

__mod_name__ = "Greetings"

NEW_MEM_HANDLER = MessageHandler(Filters.status_update.new_chat_members, new_member)
LEFT_MEM_HANDLER = MessageHandler(Filters.status_update.left_chat_member, left_member)
WELC_PREF_HANDLER = CustomCommandHandler(CMD_PREFIX, "welcome", welcome, filters=Filters.group)
GOODBYE_PREF_HANDLER = CustomCommandHandler(CMD_PREFIX, "goodbye", goodbye, filters=Filters.group)
SET_WELCOME = CustomCommandHandler(CMD_PREFIX, "setwelcome", set_welcome, filters=Filters.group)
SET_GOODBYE = CustomCommandHandler(CMD_PREFIX, "setgoodbye", set_goodbye, filters=Filters.group)
RESET_WELCOME = CustomCommandHandler(CMD_PREFIX, "resetwelcome", reset_welcome, filters=Filters.group)
RESET_GOODBYE = CustomCommandHandler(CMD_PREFIX, "resetgoodbye", reset_goodbye, filters=Filters.group)
CLEAN_WELCOME = CustomCommandHandler(CMD_PREFIX, "cleanwelcome", clean_welcome, filters=Filters.group)
WELCOMEMUTE_HANDLER = CustomCommandHandler(CMD_PREFIX, "welcomemute", welcomemute, filters=Filters.group)
DEL_JOINED_HANDLER = CustomCommandHandler(CMD_PREFIX, ["rmjoin", "cleanservice"], del_joined, filters=Filters.group)
JOIN_EVENT_HANDLER = CustomCommandHandler(CMD_PREFIX, "joinlog", join_event_log, filters=Filters.group)
WELCOME_HELP = CustomCommandHandler(CMD_PREFIX, "welcomehelp", welcome_help)
BUTTON_VERIFY_HANDLER = CallbackQueryHandler(user_button, pattern=r"user_join_")

dispatcher.add_handler(NEW_MEM_HANDLER)
dispatcher.add_handler(LEFT_MEM_HANDLER)
dispatcher.add_handler(WELC_PREF_HANDLER)
Пример #10
0
 - /setfloodtime x(m/h/d): set flood time for x time. m = minutes, h = hours, d = days. Restricts user from sending any \
messages for period.
 
If you want to flood mute someone temporarily do the following commands:
`/strongflood off`
`/setfloodtime 3h`
The above following commands will mute any spam flooders temporarily for 3 hours.

"""

__mod_name__ = "Anti-Flood"

FLOOD_BAN_HANDLER = MessageHandler(
    Filters.all & ~Filters.status_update & Filters.group, check_flood)
SET_FLOOD_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                         "setflood",
                                         set_flood,
                                         filters=Filters.group)
SET_FLOOD_TIME_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                              "setfloodtime",
                                              flood_time,
                                              filters=Filters.group)
FLOOD_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                     "flood",
                                     flood,
                                     filters=Filters.group)
FLOOD_STRENGTH_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                              "strongflood",
                                              set_flood_strength,
                                              filters=Filters.group)

dispatcher.add_handler(FLOOD_BAN_HANDLER, FLOOD_GROUP)
Пример #11
0
muting more, and more, and it gets painful. With Global muting enforcing in your chat, {}'s admins actively \
muting spammers, trolls and unsavoury characters.

Global mutes will actively engage in muting spammers, you'd have to worry-less on spammers joining in and {} will \
remove them from your group quickly as possible.

You can disable the Global mutes by `/gmutestat off` or enable `/gmutestat on`.

*Admin only:*
 - /gmutestat <on/off/yes/no>: Will disable the effect of global mutes on your group, or return your current settings.
 - /gmutealert <on/off/yes/no>: Whether or not send global mute notification in the chat upon user join/speak in the chat.
""".format(dispatcher.bot.first_name, dispatcher.bot.first_name)

__mod_name__ = "Global Mutes"

GMUTE_HANDLER = CustomCommandHandler(CMD_PREFIX, ["fmute", "gmute"], fmute,
                              filters=CustomFilters.sudo_filter | CustomFilters.support_filter)
UNGMUTE_HANDLER = CustomCommandHandler(CMD_PREFIX, ["unfmute", "ungmute"], ungmute,
                              filters=CustomFilters.sudo_filter | CustomFilters.support_filter)
GMUTE_LIST = CustomCommandHandler(CMD_PREFIX, "gmutelist", gmutelist,
                           filters=CustomFilters.sudo_filter | CustomFilters.support_filter)
                           
GMUTE_STATUS = CustomCommandHandler(CMD_PREFIX, "gmutestat", gmutestat, filters=Filters.group)
GMUTE_ALERT = CustomCommandHandler(CMD_PREFIX, "gmutealert", gmutealert, filters=Filters.group)

GMUTE_ENFORCER = MessageHandler(Filters.all & Filters.group, enforce_gmute)

dispatcher.add_handler(GMUTE_HANDLER)
dispatcher.add_handler(UNGMUTE_HANDLER)
dispatcher.add_handler(GMUTE_LIST)
dispatcher.add_handler(GMUTE_STATUS)
dispatcher.add_handler(GMUTE_ALERT)
Пример #12
0
An example of setting multiword warns filter:
`- /addwarn "very angry" This is an angry user`

This will automatically warn a user that triggers "very angry", with reason of 'This is an angry user'.

An example of how to set a new multiword warning:
`/warn @user Because warning is fun`

This will warn the user called @user, with a reason of 'Because warning is fun'
"""

__mod_name__ = "Warnings"

WARN_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                    "warn",
                                    warn_user,
                                    filters=Filters.group)
RESET_WARN_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                          ["resetwarn", "resetwarns"],
                                          reset_warns,
                                          filters=Filters.group)
REMOVE_WARNS_HANDLER = CustomCommandHandler(CMD_PREFIX, ["rmwarn", "unwarn"],
                                            remove_warns,
                                            filters=Filters.group)
CALLBACK_QUERY_HANDLER = CallbackQueryHandler(button, pattern=r"rm_warn")
MYWARNS_HANDLER = DisableAbleCommandHandler(CMD_PREFIX,
                                            "warns",
                                            warns,
                                            filters=Filters.group)
ADD_WARN_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                        "addwarn",
Пример #13
0
        elif excp.message in RUNMUTE_ERRORS:
            message.reply_text(excp.message)
        else:
            LOGGER.warning(update)
            LOGGER.exception(
                "ERROR unmnuting user %s in chat %s (%s) due to %s", user_id,
                chat.title, chat.id, excp.message)
            message.reply_text("Well damn, I can't unmute that user.")


__help__ = ""

__mod_name__ = "Remote Commands"

RBAN_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                    "rban",
                                    rban,
                                    filters=CustomFilters.sudo_filter)
RUNBAN_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                      "runban",
                                      runban,
                                      filters=CustomFilters.sudo_filter)
RKICK_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                     "rkick",
                                     rkick,
                                     filters=CustomFilters.sudo_filter)
RMUTE_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                     "rmute",
                                     rmute,
                                     filters=CustomFilters.sudo_filter)
RUNMUTE_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                       "runmute",
Пример #14
0
*Admin only:*
 - /reports <on/off>: change report setting, or view current status.
   - If done in pm, toggles your status.
   - If in chat, toggles that chat's status.
 - /solve <reason>: reply to a message to solve the report.
 - /solved: same as /solve.

To report a user, simply reply to his message with @admin or /report; \
{} will then reply with a message stating that admins have been notified.
You MUST reply to a message to report a user; you can't just use @admin to tag admins for no reason!

Note that the report commands do not work when admins use them; or when used to report an admin. {} assumes that \
admins don't need to report, or be reported!
""".format(dispatcher.bot.first_name, dispatcher.bot.first_name)

REPORT_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                      "report",
                                      report,
                                      filters=Filters.group)
SOLVE_HANDLER = CustomCommandHandler(CMD_PREFIX, ["solve", "solved"],
                                     report_solve,
                                     filters=Filters.group)
SETTING_HANDLER = CustomCommandHandler(CMD_PREFIX, "reports", report_setting)
ADMIN_REPORT_HANDLER = MessageHandler(Filters.regex("(?i)@admin(s)?"), report)

dispatcher.add_handler(REPORT_HANDLER, REPORT_GROUP)
dispatcher.add_handler(SOLVE_HANDLER, REPORT_GROUP)
dispatcher.add_handler(ADMIN_REPORT_HANDLER, REPORT_GROUP)
dispatcher.add_handler(SETTING_HANDLER)
Пример #15
0
Log channels can help you keep track of exactly what the other admins are doing. \
bans, mutes, warns, notes - everything can be moderated.

*Admin only:*
- /logchannel: get log channel info
- /setlog: set the log channel.
- /unsetlog: unset the log channel.

Setting the log channel is done by:
- Add the bot to your channel, as an admin. This is done via the "add administrators" tab.
- Send /setlog to your channel.
- Forward the /setlog command to the group you wish to be logged.
- Congratulations! All is set!
""".format(dispatcher.bot.first_name)

    __mod_name__ = "Log Channels"

    LOG_HANDLER = CustomCommandHandler(CMD_PREFIX, "logchannel", logging)
    SET_LOG_HANDLER = CustomCommandHandler(CMD_PREFIX, "setlog", setlog)
    UNSET_LOG_HANDLER = CustomCommandHandler(CMD_PREFIX, "unsetlog", unsetlog)

    dispatcher.add_handler(LOG_HANDLER)
    dispatcher.add_handler(SET_LOG_HANDLER)
    dispatcher.add_handler(UNSET_LOG_HANDLER)

else:
    # run anyway if module not loaded
    def loggable(func):
        return func
Пример #16
0
from natalie_bot.modules.helper_funcs.filters import CustomFilters

from natalie_bot import dispatcher, OWNER_ID, iSUDO_USERS, CMD_PREFIX


@run_async
@bot_admin
def getlink(update: Update, context: CallbackContext):
    if context.args:
        chat_id = int(context.args[0])
    else:
        update.effective_message.reply_text(
            "You don't seem to be referring to a chat")
    chat = context.bot.get_chat(chat_id)
    bot_member = chat.get_member(context.bot.id)
    if bot_member.can_invite_users:
        invitelink = context.bot.exportChatInviteLink(chat_id)
        update.effective_message.reply_text(invitelink)
    else:
        update.effective_message.reply_text(
            "I don't have access to the invite link!")


GETLINK_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                       "getlink",
                                       getlink,
                                       filters=Filters.user(OWNER_ID)
                                       | CustomFilters.isudo_filter)

dispatcher.add_handler(GETLINK_HANDLER)
Пример #17
0
*Admin only:*
 - /setrules <your rules here>: set the rules for this chat.
 - /clearrules: clear the rules for this chat.
 - /chatrules <yes/no/on/off>: should the rules be sent to chat. Default: no.

"""

__mod_name__ = "Rules"

GET_RULES_HANDLER = DisableAbleCommandHandler(CMD_PREFIX,
                                              "rules",
                                              get_rules,
                                              filters=Filters.group)
SET_RULES_MODE = CustomCommandHandler(CMD_PREFIX,
                                      "chatrules",
                                      chat_rules,
                                      filters=Filters.group)
SET_RULES_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                         "setrules",
                                         set_rules,
                                         filters=Filters.group)
RESET_RULES_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                           "clearrules",
                                           clear_rules,
                                           filters=Filters.group)

dispatcher.add_handler(GET_RULES_HANDLER)
dispatcher.add_handler(SET_RULES_HANDLER)
dispatcher.add_handler(SET_RULES_MODE)
dispatcher.add_handler(RESET_RULES_HANDLER)
Пример #18
0
 - /addblacklist <triggers>: Add a trigger to the blacklist. Each line is considered one trigger, so using different \
lines will allow you to add multiple triggers.
 - /unblacklist <triggers>: Remove triggers from the blacklist. Same newline logic applies here, so you can remove \
multiple triggers at once.
 - /rmblacklist <triggers>: Same as above.
 
Tip: To copy list of saved blacklist simply use `/blacklist copy`, {} will send non-bulleted list of blacklist.
""".format(dispatcher.bot.first_name)

BLACKLIST_HANDLER = DisableAbleCommandHandler(CMD_PREFIX,
                                              "blacklist",
                                              blacklist,
                                              filters=Filters.group,
                                              admin_ok=True)
ADD_BLACKLIST_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                             "addblacklist",
                                             add_blacklist,
                                             filters=Filters.group)
UNBLACKLIST_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                           ["unblacklist", "rmblacklist"],
                                           unblacklist,
                                           filters=Filters.group)
BLACKLIST_DEL_HANDLER = MessageHandler(
    (Filters.text | Filters.command | Filters.sticker | Filters.photo)
    & Filters.group, del_blacklist)

dispatcher.add_handler(BLACKLIST_HANDLER)
dispatcher.add_handler(ADD_BLACKLIST_HANDLER)
dispatcher.add_handler(UNBLACKLIST_HANDLER)
dispatcher.add_handler(BLACKLIST_DEL_HANDLER, group=BLACKLIST_GROUP)
Пример #19
0
        for domain in all_whitelisted:
            filter_list += "<code>{}</code>\n".format(html.escape(domain))
    else:
        for domain in all_whitelisted:
            filter_list += " • <code>{}</code>\n".format(html.escape(domain))

    split_text = split_message(filter_list)
    for text in split_text:
        if text == BASE_WHITELIST_STRING:
            msg.reply_text("There are no whitelisted domains here!")
            return
        msg.reply_text(text.format(chat_name), parse_mode=ParseMode.HTML)


ADD_URL_WHITELIST_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                                 "addwhitelist",
                                                 add_whitelist_url,
                                                 filters=Filters.group)
RM_WHITELIST_URL_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                                ["unwhitelist", "rmwhitelist"],
                                                rm_whitelist_url,
                                                filters=Filters.group)
GET_WHITELISTED_URLS = DisableAbleCommandHandler(CMD_PREFIX,
                                                 "whitelist",
                                                 get_whitelisted_urls,
                                                 filters=Filters.group,
                                                 admin_ok=True)

__mod_name__ = "Domain whitelists"

dispatcher.add_handler(ADD_URL_WHITELIST_HANDLER)
dispatcher.add_handler(RM_WHITELIST_URL_HANDLER)
Пример #20
0
                                               sql.num_chats())


def __gdpr__(user_id):
    sql.del_user(user_id)


def __migrate__(old_chat_id, new_chat_id):
    sql.migrate_chat(old_chat_id, new_chat_id)


__help__ = ""  # no help string

__mod_name__ = "Users"

BROADCAST_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                         "broadcast",
                                         broadcast,
                                         filters=Filters.user(OWNER_ID)
                                         | CustomFilters.isudo_filter)
USER_HANDLER = MessageHandler(Filters.all & Filters.group, log_user)
CHATLIST_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                        "chatlist",
                                        chats,
                                        filters=Filters.user(OWNER_ID)
                                        | CustomFilters.isudo_filter)

dispatcher.add_handler(USER_HANDLER, USERS_GROUP)
dispatcher.add_handler(BROADCAST_HANDLER)
dispatcher.add_handler(CHATLIST_HANDLER)
Пример #21
0
from telegram import Update, Bot
from telegram.error import BadRequest
from telegram.ext import MessageHandler, Filters, CommandHandler, CallbackContext
from telegram.ext.dispatcher import run_async
from typing import List
from natalie_bot.modules.helper_funcs.filters import CustomFilters
from natalie_bot.modules.helper_funcs.handlers import CustomCommandHandler

import telegram
from natalie_bot import dispatcher, OWNER_ID, iSUDO_USERS, CMD_PREFIX

@run_async
def leave(update: Update, context: CallbackContext):
    if context.args:
        chat_id = str(context.args[0])
        del context.args[0]
        try:
            context.bot.leave_chat(int(chat_id))
            update.effective_message.reply_text("Left the group successfully!")
        except telegram.TelegramError:
            update.effective_message.reply_text("Attempt failed.")
    else:
        update.effective_message.reply_text("Give me a valid chat id") 

__help__ = ""

__mod_name__ = "Leave"

LEAVE_HANDLER = CustomCommandHandler(CMD_PREFIX, "leave", leave, filters=Filters.user(OWNER_ID) | CustomFilters.isudo_filter)
dispatcher.add_handler(LEAVE_HANDLER)
Пример #22
0
tidy and simplified.

Here is an example of using buttons:
You can create a button using `[Name of button text](buttonurl://example.com)`.

If you wish to add more than 1 buttons simply do the following:
`[Button 1](buttonurl://example.com)`
`[Button 2](buttonurl://github.com:same)`
`[Button 3](buttonurl://google.com)`

The `:same` end of the link merges 2 buttons on same line as 1 button, resulting in 3 button to be separated \
from same line.

""".format(dispatcher.bot.first_name, dispatcher.bot.first_name)

__mod_name__ = "Filters"

FILTER_HANDLER = CustomCommandHandler(CMD_PREFIX, "filter", filters)
STOP_HANDLER = CustomCommandHandler(CMD_PREFIX, "stop", stop_filter)
LIST_HANDLER = DisableAbleCommandHandler(CMD_PREFIX,
                                         "filters",
                                         list_handlers,
                                         admin_ok=True)
CUST_FILTER_HANDLER = MessageHandler(CustomFilters.has_text, reply_filter,
                                     Filters.update.edited_message)

dispatcher.add_handler(FILTER_HANDLER)
dispatcher.add_handler(STOP_HANDLER)
dispatcher.add_handler(LIST_HANDLER)
dispatcher.add_handler(CUST_FILTER_HANDLER, HANDLER_GROUP)
Пример #23
0
                   "\n<b>• ID:</b> <code>{}</code>".format(html.escape(chat.title),
                                              mention_html(user.id, user.first_name),
                                              mention_html(member.user.id, member.user.first_name), user_id)
            if reason:
                log += "\n<b>• Reason:</b> {}".format(reason)
            return log

    return ""


__help__ = ""

__mod_name__ = "Muting & Restricting"

MUTE_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                    "mute",
                                    mute,
                                    filters=Filters.group)
SMUTE_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                     "smute",
                                     smute,
                                     filters=Filters.group)
UNMUTE_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                      "unmute",
                                      unmute,
                                      filters=Filters.group)
TEMPMUTE_HANDLER = CustomCommandHandler(CMD_PREFIX, ["tmute", "tempmute"],
                                        temp_mute,
                                        filters=Filters.group)
TEMP_NOMEDIA_HANDLER = CustomCommandHandler(CMD_PREFIX,
                                            ["trestrict", "temprestrict"],
                                            temp_nomedia,
Пример #24
0
 
 An example of how to save a note would be via:
`/save data This is some data!`

Now, anyone using "/get notedata", or "#notedata" will be replied to with "This is some data!".

If you want to save an image, gif, or sticker, or any other data, do the following:
`/save notename` while replying to a sticker or whatever data you'd like. Now, the note at "#notename" contains a sticker which will be sent as a reply.

Tip: to retrieve a note without the formatting, use /get <notename> noformat
This will retrieve the note and send it without formatting it; getting you the raw markdown, allowing you to make easy edits.
"""

__mod_name__ = "Notes"

GET_HANDLER = CustomCommandHandler(CMD_PREFIX, "get", cmd_get)
HASH_GET_HANDLER = MessageHandler(Filters.regex(r"^#[^\s]+"), hash_get)

SAVE_HANDLER = CustomCommandHandler(CMD_PREFIX, "save", save)
DELETE_HANDLER = CustomCommandHandler(CMD_PREFIX, "clear", clear)

LIST_HANDLER = DisableAbleCommandHandler(CMD_PREFIX, ["notes", "saved"],
                                         list_notes,
                                         admin_ok=True)

dispatcher.add_handler(GET_HANDLER)
dispatcher.add_handler(SAVE_HANDLER)
dispatcher.add_handler(LIST_HANDLER)
dispatcher.add_handler(DELETE_HANDLER)
dispatcher.add_handler(HASH_GET_HANDLER)
Пример #25
0
bans spammers, trolls and unsavoury characters.

Global bans will actively engage in banning spammers, you'd have to worry-less on spammers joining in and {} will \
remove them from your group quickly as possible.

You can disable the Global bans by `/gbanstat off` or enable `/gbanstat on`.

*Admin only:*
 - /gbanstat <on/off/yes/no>: Will disable the effect of global bans on your group, or return your current settings.
 - /gbanalert <on/off/yes/no>: Whether or not send global ban notification in the chat upon user join/speak in the chat.
""".format(dispatcher.bot.first_name, dispatcher.bot.first_name)

__mod_name__ = "Global Bans"

GBAN_HANDLER = CustomCommandHandler(CMD_PREFIX, ["fban", "gban"],
                                    gban,
                                    filters=CustomFilters.sudo_filter
                                    | CustomFilters.support_filter)
UNGBAN_HANDLER = CustomCommandHandler(CMD_PREFIX, ["unfban", "ungban"],
                                      ungban,
                                      filters=CustomFilters.sudo_filter
                                      | CustomFilters.support_filter)
GBAN_LIST = CustomCommandHandler(CMD_PREFIX,
                                 "gbanlist",
                                 gbanlist,
                                 filters=CustomFilters.sudo_filter
                                 | CustomFilters.support_filter)
GBAN_STATUS = CustomCommandHandler(CMD_PREFIX,
                                   "gbanstat",
                                   gbanstat,
                                   filters=Filters.group)
GBAN_ALERT = CustomCommandHandler(CMD_PREFIX,
Пример #26
0
                "reported makes me better! Thanks! :)")
            LOGGER.exception("Import for chatid %s with name %s failed.",
                             str(chat.id), str(chat.title))
            return

        # TODO: some of that link logic
        # NOTE: consider default permissions stuff?
        msg.reply_text("Backup fully imported. Welcome back! :D")


@run_async
@user_admin
def export_data(update: Update, context: CallbackContext):
    msg = update.effective_message  # type: Optional[Message]
    msg.reply_text("")


__mod_name__ = "Backups"

__help__ = """
*Admin only:*
 - /import: reply to a group butler backup file to import as much as possible, making the transfer super simple! Note \
that files/photos can't be imported due to telegram restrictions.
 - /export: !!! This isn't a command yet, but should be coming soon!
"""
IMPORT_HANDLER = CustomCommandHandler(CMD_PREFIX, "import", import_data)
EXPORT_HANDLER = CustomCommandHandler(CMD_PREFIX, "export", export_data)

dispatcher.add_handler(IMPORT_HANDLER)
# dispatcher.add_handler(EXPORT_HANDLER)