time_val = int(args[0])
    unit = 'seconds'

    if (time_val < 0):
        return [-1, "I can't go back in time nya (╥_╥)\nAsk that old vampire hag KissShot if you want to do that"]
    if len(args) > 1:
        unit = units[args[1]] if args[1] in units else args[1]

    if unit in ['months', 'years', 'decades', 'centuries', 'millennia'] or (unit == 'days' and time_val > 30):
        return [-1,
                "I don't know if I'll live that long nya (╥_╥)\nA shorter time(upto 30 days) is all I can handle at moment"]
    else:
        if unit not in multiplier:
            raise ValueError("Unexpected arguments")

    return [time_val * multiplier[unit],
            "Wakathawa nyaa(=^-ω-^=). Meow will remind you in %d %s" % (time_val, unit)]


def alarm(context):
    """Send the alarm message."""
    job = context.job
    context.bot.send_message(job.context['chat_id'], text='@%s Nyaaan! Your reminder is here!' % (job.context['user']))


remind_handler = CommandHandler("remindme", set_reminder,
                                pass_args=True,
                                pass_job_queue=True,
                                pass_chat_data=True)
dispatcher.add_handler(remind_handler)
Ejemplo n.º 2
0
HELP_MESSAGE = (
    "Nyeko is here to help nyaa!\n\nTo see all commands I respond to, use /list\nTo get the usage of a "
    "particular command use /help <command>\n\nIf you "
    "have any other queries or want to request new features, head over to the [support group]("
    "https://t.me/NekoHanekawaGroup)\n")


def help(update: Update, context: Context):
    try:
        command = context.args[0]
        if command[0] == '/':
            command = command[1:]

        update.message.reply_markdown(COMMAND_LIST[command])

    except(ValueError, IndexError):
        update.message.reply_markdown(HELP_MESSAGE)


def list_all(update: Update, context: Context):
    commands = '/' + '\n/'.join(COMMAND_LIST.keys())
    update.message.reply_text("List of available commands:\n%s" % (commands))


help_handler = CommandHandler('help', help)
dispatcher.add_handler(help_handler)

list_handler = CommandHandler('list', list_all)
dispatcher.add_handler(list_handler)
from src import dispatcher

from telegram import Update
from telegram.ext import CallbackContext as Context, run_async, MessageHandler, Filters


@run_async
def welcome(update: Update, context: Context):
    new_members = update.effective_message.new_chat_members
    for new_mem in new_members:
        if new_mem.id == context.bot.id:
            update.effective_message.reply_text(
                "Thankyou for adding me to %s!\nUse /help to see how I can help you"
                % update.effective_chat.title)
            continue
        update.effective_message.reply_text(
            "Yokoso %s!\nWelcome to %s" %
            (new_mem.first_name, update.effective_chat.title))


welcome_handler = MessageHandler(Filters.status_update.new_chat_members,
                                 welcome)
dispatcher.add_handler(welcome_handler)
Ejemplo n.º 4
0
from src import dispatcher

from telegram import Update
from telegram.ext import CommandHandler, CallbackContext as Context

START_MESSAGE = (
    "Kyonichwa nyaaan!  V(=^・ω・^=)v\n\nI'm Neko Hanekawa. I'm the cat girl who'll take good care of your groups "
    "in exchange for headpats. (=^-ω-^=)\n\nTo see what all I can do as of now use /help.\nI'm still growing. "
    "Help me grow faster by joining the support group [here](https://t.me/NekoHanekawaGroup) or "
    "contribute to me on [GithHub](https://github.com/kpathul/Hanekawa-Telegram-Bot/)\n\nMy owner is "
    "@DiscipleOfDisaster\n\nSore ja\nヽ(=^・ω・^=)丿")


def start(update: Update, context: Context):
    update.message.reply_markdown(START_MESSAGE)


start_handler = CommandHandler('start', start)
dispatcher.add_handler(start_handler)
Ejemplo n.º 5
0
def unpin(update: Update, context: Context):
    requesting_member = update.effective_chat.get_member(update.effective_user.id)

    if requesting_member.status not in ADMINS:
        update.message.reply_text("Only admins can unpin messages")
    else:
        try:
            context.bot.unpin_chat_message(update.effective_chat.id)
            update.message.reply_text("Done. Message unpinned")
        except TelegramError:
            update.message.reply_text("No message has been pinned")


promote_handler = CommandHandler('promote', promote)
dispatcher.add_handler(promote_handler)

demote_handler = CommandHandler('demote', demote)
dispatcher.add_handler(demote_handler)

mute_handler = CommandHandler('mute', mute)
dispatcher.add_handler(mute_handler)

unmute_handler = CommandHandler('unmute', unmute)
dispatcher.add_handler(unmute_handler)

kick_handler = CommandHandler(['kick', 'ban'], kick)
dispatcher.add_handler(kick_handler)

unban_handler = CommandHandler('unban', unban)
dispatcher.add_handler(unban_handler)
from src import dispatcher

from telegram import Update
from telegram.ext import CommandHandler, CallbackContext as Context

NEW_FEATURES = (
    "I'm now hosted on a remote server! This means I'll be active all the time!\n"
    "I now promote, demote, mute and kick members and pin messages.\n"
    "Also try /xkcd for new year surprise!\n\n "
    "Note: To be more inclusive, unfortunately my anime theme is getting slowly removed and will be "
    "completely down by next update (ノ﹏ヽ)")
NEXT_FEATURES = (
    "My creator is always giving me new powers nyaa!\nI'll be getting a database soon.\n"
    "Look forward to it! (=^・ω・^=)")


def whats_new(update: Update, context: Context):
    update.message.reply_markdown(NEW_FEATURES)


def whats_next(update: Update, context: Context):
    update.message.reply_markdown(NEXT_FEATURES)


wnext_handler = CommandHandler('whatsnext', whats_next)
dispatcher.add_handler(wnext_handler)

wnew_handler = CommandHandler('whatsnew', whats_new)
dispatcher.add_handler(wnew_handler)
Ejemplo n.º 7
0
from src import dispatcher
from src.helper_functions import xkcd_meme

from telegram import Update
from telegram.ext import CommandHandler, CallbackContext as Context

from random import randint


def xkcd(update: Update, context: Context):
    COMIC_NO = randint(1, 2248)
    try:
        meme = xkcd_meme.Meme(COMIC_NO).getImageUrl()
        if meme:
            update.message.reply_photo(meme)
        else:
            update.message.reply_text("xkcd server seems to be down")

    except ValueError:
        update.message.reply_text(ValueError)


meme_handler = CommandHandler("xkcd", xkcd)
dispatcher.add_handler(meme_handler)