Ejemplo n.º 1
0
def cat(bot, update):
    from chats_data import chats_data

    msg = update.message
    chat_id = msg.chat_id
    msg_id = msg.message_id

    if not chats_data.get(chat_id, None) or not chats_data[chat_id].get(
            'cat', None):
        bot.send_message(
            chat_id=msg.chat_id,
            text=
            "The /cat plugin is disabled. You can enable it using `/enable cat` or by /plugins.",
            reply_to_message_id=msg.message_id,
            parse_mode='Markdown')
        return

    url = "https://api.thecatapi.com/v1/images/search?size=med&mime_types=jpg&format=json&order=RANDOM&page=0&limit=1"

    api_key = "93d5063b-edb9-41da-b124-88409869b1ce"
    headers = {'Content-Type': 'application/json', 'x-api-key': api_key}

    response = requests.get(url, headers=headers)
    data = response.json()

    try:
        image_url = data[0]['url']
        bot.send_photo(chat_id=chat_id,
                       photo=image_url,
                       reply_to_message_id=msg_id)
    except:
        bot.send_message(chat_id=msg.chat_id,
                         text="Something went wrong...",
                         reply_to_message_id=msg.message_id,
                         parse_mode='Markdown')
Ejemplo n.º 2
0
def weeb(bot, update):
	from chats_data import chats_data

	msg = update.message
	chat_id = msg.chat_id
	
	if not chats_data.get(chat_id, None) or not chats_data[chat_id].get('weeb', None):
		bot.send_message(chat_id = msg.chat_id, 
						 text = "The /weeb plugin is disabled. You can enable it using `/enable weeb` or by /plugins.", 
						 reply_to_message_id = msg.message_id,
						 parse_mode = 'Markdown')
		return

	text = ''
	msg_list = msg.text.strip().split(' ', 1)
	if len(msg_list) > 1:
		text += msg_list[1].strip().replace('&', '')
	else:
		text += 'なに?'

	key = '52dc0dd127cf41688047c8a10af4fbc0'
	url = f'http://api.voicerss.org/?key={key}&hl=ja-jp&src={text}&r=-3'

	data = requests.get(url)
	audio_data = data._content
	audio = open('audio.mp3', 'wb')
	audio.write(audio_data)
	audio.close()
	audio = open('audio.mp3', 'rb')
	bot.send_audio(chat_id = msg.chat_id,
				   audio = audio,
				   reply_to_message_id = msg.message_id)
	audio.close()
Ejemplo n.º 3
0
def save_list(bot, update):
    from save_dict import save_dict
    from chats_data import chats_data
    chat_id = update.message.chat_id
    chat_title = update.message.chat.title

    if chats_data.get(chat_id, None) and chats_data[chat_id].get('save', None):
        if chat_id in save_dict.keys():
            if save_dict[chat_id]:
                msg = f'Saves for {chat_title}:\n'
                save_list = save_dict[chat_id].keys()
                for save_name in save_list:
                    msg += f'`{save_name}`\n'
                bot.send_message(chat_id=update.message.chat_id,
                                 text=msg,
                                 parse_mode='Markdown',
                                 reply_to_message_id=update.message.message_id)
            else:
                bot.send_message(
                    chat_id=update.message.chat_id,
                    text='Saves have not been added yet. Use /save to add.',
                    parse_mode='Markdown',
                    reply_to_message_id=update.message.message_id)
        else:
            bot.send_message(
                chat_id=update.message.chat_id,
                text='Saves have not been added yet. Use /save to add',
                parse_mode='Markdown',
                reply_to_message_id=update.message.message_id)
Ejemplo n.º 4
0
def warn(bot, update):
    import pickle
    from chats_data import chats_data

    msg = update.message
    chat_id = msg.chat_id

    if not chats_data.get(chat_id, None) or not chats_data[chat_id].get('warn', None):
        bot.send_message(chat_id=msg.chat_id,
                         text="The /warn plugin is disabled. You can enable it using `/enable warn` or by /plugins.",
                         reply_to_message_id=msg.message_id,
                         parse_mode='Markdown')
        return

    warned_id = msg.reply_to_message and msg.reply_to_message.from_user.id

    warner = bot.get_chat_member(chat_id, msg.from_user.id)['status']
    warned = warned_id and bot.get_chat_member(chat_id, warned_id)['status']

    # print(f'{warner} is warning {warned}')

    if warner in ['administrator', 'creator']:
        if not warned:
            bot.send_message(chat_id=msg.chat_id,
                             text="Reply to the user that you want to warn.",
                             reply_to_message_id=msg.message_id)

        if warned_id == msg.from_user.id:
            bot.send_message(chat_id=msg.chat_id,
                             text="You cannot warn yourself.",
                             reply_to_message_id=msg.message_id)

        elif warned in ['administrator', 'creator']:
            bot.send_message(chat_id=msg.chat_id,
                             text="I wish I could warn admins...",
                             reply_to_message_id=msg.message_id)

        elif warned == 'left':
            bot.send_message(chat_id=chat_id,
                             text="Can't warn user, they already left.",
                             reply_to_message_id=msg.message_id)

        elif warned == 'kicked':
            bot.send_message(chat_id=chat_id,
                             text="Can't warn user, I already kicked them.",
                             reply_to_message_id=msg.message_id)

        elif warned == 'member':
            text = msg.text.strip().split(" ", 1)
            if len(text) > 1:
                warn_text = check_warn(bot, update, warned_id)
                bot.send_message(chat_id=chat_id, text=f"*{warn_text}*\n*Reason:* _{text[1]}_", parse_mode="Markdown", reply_to_message_id=msg.reply_to_message.message_id)
            else:
                text = check_warn(bot, update, warned_id)
                bot.send_message(chat_id=chat_id, text=f"*{text}*", parse_mode="Markdown", reply_to_message_id=msg.reply_to_message.message_id)

    elif warner not in ['creator', 'administrator']:
        bot.send_message(chat_id=chat_id,
                         text="F**k off.",
                         reply_to_message_id=msg.message_id)
Ejemplo n.º 5
0
def rules(bot, update):
	from chats_data import chats_data

	msg = update.message
	chat_id = update.message.chat_id

	if not chats_data.get(chat_id, None) or not chats_data[chat_id].get('rules', None):
		bot.send_message(chat_id = msg.chat_id, 
						 text = "The /rules plugin is disabled. You can enable it using `/enable rules` or by /plugins.", 
						 reply_to_message_id = msg.message_id,
						 parse_mode = 'Markdown')
		return

	from rules_dict import rules_dict

	if chat_id in rules_dict:
		chat_rules = rules_dict[chat_id]
		bot.send_message(chat_id = msg.chat_id, 
						 text = f"*Rules:*\n{chat_rules}",
						 reply_to_message_id = msg.message_id,
						 parse_mode = 'Markdown')
	else:
		bot.send_message(chat_id = msg.chat_id, 
						 text = "_There are no rules set for this chat._",
						 reply_to_message_id = msg.message_id,
						 parse_mode = 'Markdown')
Ejemplo n.º 6
0
def remove_filter(bot, update):
	from chats_data import chats_data
	from filter_dict import filter_dict
	chat_id = update.message.chat_id
	msg = update.message.text
	if chats_data.get(chat_id, None) and chats_data[chat_id].get('filters', None):
		user = bot.get_chat_member(chat_id, update.message.from_user.id)['status']
		if user in ["administrator", "creator"]:
			msg_list = msg.strip().split(' ', 1)

			if len(msg_list) == 2:
				trigger = msg_list[1].lower().strip()
				if chat_id in filter_dict.keys():
					if trigger in filter_dict[chat_id].keys():
						del filter_dict[chat_id][trigger]

						from pickle import dump
						filter_db = open('filter.db', 'wb')
						dump(filter_dict, filter_db)
						filter_db.close()

						bot.send_message(chat_id = update.message.chat_id, text = f'Successfully deleted `{trigger}`', parse_mode = 'Markdown', reply_to_message_id = update.message.message_id)
					else:
						bot.send_message(chat_id = update.message.chat_id, text = "Such a filter doesn't exist for your group.", parse_mode = 'Markdown', reply_to_message_id = update.message.message_id)
				else:
					bot.send_message(chat_id = update.message.chat_id, text = "Filters have not been added yet", parse_mode = 'Markdown', reply_to_message_id = update.message.message_id)
			else:
				bot.send_message(chat_id = update.message.chat_id, text = "*Format:*\n/stop _filter_\__name_", parse_mode = 'Markdown', reply_to_message_id = update.message.message_id)
		else:
			bot.send_message(chat_id = update.message.chat_id, text = "F**k off.", parse_mode = 'Markdown', reply_to_message_id = update.message.message_id)
	else:
		bot.send_message(chat_id = update.message.chat_id, text = "The /stop command is disabled. You can enable it using `/enable filters` or by /plugins.", parse_mode = 'Markdown', reply_to_message_id = update.message.message_id)
Ejemplo n.º 7
0
def stats_check(bot, update, job_queue):
    from stats_dict import stats_dict
    from chats_data import chats_data
    from global_stats import global_stats_dict
    from time import gmtime, strftime

    msg = update.message
    user = msg.from_user.id
    chat_id = update.message.chat_id
    user_object = msg.from_user

    if not chats_data.get(chat_id, None) or not chats_data[chat_id].get(
            'stats', None):
        return

    increment(stats_dict, chat_id, user_object)
    increment(global_stats_dict, chat_id, user_object)

    from pickle import dump
    stats_db = open('stats.db', 'wb')
    dump(stats_dict, stats_db)
    stats_db.close()

    global_stats_db = open('global_stats.db', 'wb')
    dump(global_stats_dict, global_stats_db)
    global_stats_db.close()
Ejemplo n.º 8
0
def gstats(bot, update):
    from chats_data import chats_data
    from global_stats import global_stats_dict
    from times import month_dict

    msg = update.message
    chat_id = msg.chat_id
    chat_title = msg.chat.title

    if not chats_data.get(chat_id, None) or not chats_data[chat_id].get(
            'stats', None):
        bot.send_message(
            chat_id=msg.chat_id,
            text=
            "The /stats plugin is disabled. You can enable it using `/enable stats` or by /plugins.",
            reply_to_message_id=msg.message_id,
            parse_mode='Markdown')
        return
    if 'generated' in global_stats_dict[chat_id].keys():
        generated = global_stats_dict[chat_id]["generated"]
        generated = generated.split("-", 2)
        year = generated[0]
        month = month_dict[int(generated[1])]
        date = generated[2]

        if int(date) % 10 == 3 and int(date) / 10 != 1:
            date = str(date) + "rd"
        elif int(date) % 10 == 2 and int(date) / 10 != 1:
            date = str(date) + "nd"
        elif int(date) % 10 == 1 and int(date) / 10 != 1:
            date = str(date) + "st"
        else:
            date = str(date) + "th"

        text = f"Stats for {chat_title}:\nGenerated on {date} {month}, {year}.\n\n"
    else:  #Means we are counting before i made generated. I implemented this shit on 19th August
        text = f'Stats for {chat_title}:\nGenerated on 19th August, 2018.\n\n'
    user_list, value_list = desc(global_stats_dict, chat_id)

    with open('stats.txt', 'w') as file:
        for index, user in enumerate(user_list, 0):
            if user != "total_messages" and "generated":
                messages = value_list[index]
                if messages == 1:
                    messages = str(messages) + " message"
                else:
                    messages = str(messages) + " messages."

                percentage = round(
                    (value_list[index] /
                     global_stats_dict[chat_id]['total_messages']) * 100, 2)
                text += f"{index+1}.{user.first_name} - {value_list[index]} [{percentage}%]\n"
        file.write(text)
    file = open('stats.txt', 'rb')
    bot.send_document(chat_id=msg.chat_id,
                      document=file,
                      reply_to_message_id=msg.message_id)
    file.close()
Ejemplo n.º 9
0
def youtube(bot, update):
    from chats_data import chats_data

    msg = update.message
    chat_id = msg.chat_id
    msg_id = msg.message_id

    if not chats_data.get(chat_id, None) or not chats_data[chat_id].get(
            'youtube', None):
        bot.send_message(
            chat_id=msg.chat_id,
            text=
            "The /youtube plugin is disabled. You can enable it using `/enable youtube` or by /plugins.",
            reply_to_message_id=msg_id,
            parse_mode='Markdown')
        return

    msg_list = msg.text.split(' ', 1)[1].split()
    pprint(msg_list)
    for member in msg_list:
        member = member.lstrip('http://').lstrip('https://').lstrip('www.')

        if member.startswith('youtu.be/'):
            video_id = member[len('youtu.be/'):]
            if '?' in video_id:
                tags_index = video_id.index('?')
                video_id = video_id[:tags_index]
        elif member.startswith('youtube.com'):
            video_id = member[len('youtube.com/watch?v='):]
            if '&' in video_id:
                tags_index = video_id.index('&')
                video_id = video_id[:tags_index]
        else:
            continue

        url = f"https://api.unblockvideos.com/youtube_downloader?id={video_id}&selector=mp4"
        response = requests.get(url)
        data = response.json()

        if type(data) == type([]):
            video_url = data[0].get('url', None)
            response = requests.get(video_url)
            video = response.content
            with open('video.mp4', 'wb') as video_file:
                video_file.write(video)
            with open('video.mp4', 'rb') as video_file:
                bot.send_video(chat_id=chat_id,
                               video=video_file,
                               reply_to_message_id=msg_id)
        else:
            bot.send_message(chat_id=chat_id,
                             text="Invalid url.",
                             reply_to_message_id=msg_id)
Ejemplo n.º 10
0
def ud(bot, update):
    from requests import get

    from chats_data import chats_data
    msg = update.message
    chat_id = msg.chat_id

    if not chats_data.get(chat_id, None) or not chats_data[chat_id].get(
            'ud', None):
        bot.send_message(
            chat_id=msg.chat_id,
            text=
            "The /ud plugin is disabled. You can enable it using `/enable ud` or by /plugins.",
            reply_to_message_id=msg.message_id,
            parse_mode='Markdown')
        return

    msg_list = msg.text.strip().split(' ', 1)
    replied_msg = msg.reply_to_message

    if len(msg_list) == 2:
        word = msg_list[1].lower()
    elif replied_msg:
        word = replied_msg.text
    else:
        bot.send_message(chat_id=update.message.chat_id,
                         text='*Format:*\n/ud _word_',
                         parse_mode='Markdown',
                         reply_to_message_id=update.message.message_id)
        return

    url = f'http://api.urbandictionary.com/v0/define?term={word}'

    response = get(url)
    data = response.json()

    if data['list']:
        first_answer = data['list'][0]

        heading = first_answer['word']
        definition = first_answer['definition']
        example = first_answer['example']

        reply = f"*{heading}*\n\n{definition}\n\n_{example}_"
        bot.send_message(chat_id=chat_id,
                         text=reply,
                         reply_to_message_id=msg.message_id,
                         parse_mode='Markdown')
    else:
        bot.send_message(chat_id=update.message.chat_id,
                         text='No entry found.',
                         reply_to_message_id=update.message.message_id)
Ejemplo n.º 11
0
def check_filters(bot, update):
	from chats_data import chats_data
	from filter_dict import filter_dict
	from re import search
	
	msg = update.message
	chat_id = msg.chat_id
	if chats_data.get(chat_id, None) and chats_data[chat_id].get('filters', None):
		txt = msg.text.lower()
		if chat_id in filter_dict.keys():
			for trigger in filter_dict[chat_id].keys():
				if search(rf"\b{trigger}\b", txt):
					bot.send_message(chat_id = chat_id, text = filter_dict[chat_id][trigger], reply_to_message_id = msg.message_id)
Ejemplo n.º 12
0
def welcome(bot, update, user_data):
    from main import start_dict
    from chats_data import chats_data
    chat_id = update.message.chat_id

    if not chats_data.get(chat_id, None) or not chats_data[chat_id].get(
            'welcome', None):
        return

    reply_markup = []

    msg = update.message
    if msg.new_chat_members:
        user_name = msg.new_chat_members[0]['username']
        if "_" in user_name:
            user_name = user_name.replace("_", "\_")

        if chat_id in start_dict.keys():
            if 'rules' in start_dict[chat_id].keys():
                from telegram import InlineKeyboardMarkup, InlineKeyboardButton

                reply_markup = InlineKeyboardMarkup([[
                    InlineKeyboardButton(
                        "Rules",
                        url=f't.me/toilet_evergarden_bot?start=rules_{chat_id}'
                    )
                ]])

        if chat_id in start_dict.keys():
            if 'welcome' in start_dict[chat_id].keys():
                text = start_dict[chat_id]['welcome']
                sent_message = bot.send_message(
                    chat_id=msg.chat_id,
                    text=text,
                    reply_to_message_id=msg.message_id,
                    parse_mode='Markdown',
                    reply_markup=reply_markup)
            else:
                sent_message = bot.send_message(
                    chat_id=msg.chat_id,
                    text=f"@{user_name} Okairi m**********r",
                    reply_to_message_id=msg.message_id,
                    parse_mode='Markdown',
                    reply_markup=reply_markup)
        else:
            sent_message = bot.send_message(
                chat_id=msg.chat_id,
                text=f"@{user_name} Okairi m**********r",
                reply_to_message_id=msg.message_id,
                parse_mode='Markdown',
                reply_markup=reply_markup)
Ejemplo n.º 13
0
def check_saves(bot, update):
    from chats_data import chats_data
    from save_dict import save_dict

    msg = update.message
    chat_id = msg.chat_id
    if chats_data.get(chat_id, None) and chats_data[chat_id].get('save', None):
        txt = msg.text.lower()
        if chat_id in save_dict.keys():
            for trigger in save_dict[chat_id].keys():
                if txt.startswith(f'#{trigger}'):
                    bot.send_message(chat_id=chat_id,
                                     text=save_dict[chat_id][trigger],
                                     reply_to_message_id=msg.message_id)
Ejemplo n.º 14
0
def remove_save(bot, update):
    from chats_data import chats_data
    from save_dict import save_dict
    chat_id = update.message.chat_id
    msg = update.message.text
    if chats_data.get(chat_id, None) and chats_data[chat_id].get('save', None):
        user = bot.get_chat_member(chat_id,
                                   update.message.from_user.id)['status']
        if user in ["administrator", "creator"]:
            msg_list = msg.strip().split(' ', 1)

            if len(msg_list) == 2:
                trigger = msg_list[1].lower().strip()
                if chat_id in save_dict.keys():
                    if trigger in save_dict[chat_id].keys():
                        del save_dict[chat_id][trigger]

                        from pickle import dump
                        save_db = open('save.db', 'wb')
                        dump(save_dict, save_db)
                        save_db.close()

                        bot.send_message(
                            chat_id=update.message.chat_id,
                            text=f'Successfully deleted `{trigger}`',
                            parse_mode='Markdown',
                            reply_to_message_id=update.message.message_id)
                    else:
                        bot.send_message(
                            chat_id=update.message.chat_id,
                            text="Such a save doesn't exist for your group.",
                            parse_mode='Markdown',
                            reply_to_message_id=update.message.message_id)
                else:
                    bot.send_message(
                        chat_id=update.message.chat_id,
                        text="Saves have not been added yet",
                        parse_mode='Markdown',
                        reply_to_message_id=update.message.message_id)
            else:
                bot.send_message(chat_id=update.message.chat_id,
                                 text="*Format:*\n/stop _save_\__name_",
                                 parse_mode='Markdown',
                                 reply_to_message_id=update.message.message_id)
        else:
            bot.send_message(chat_id=update.message.chat_id,
                             text="No.",
                             parse_mode='Markdown',
                             reply_to_message_id=update.message.message_id)
Ejemplo n.º 15
0
def stats(bot, update):
    from stats_dict import stats_dict
    from chats_data import chats_data

    msg = update.message
    chat_id = msg.chat_id
    chat_title = msg.chat.title

    if not chats_data.get(chat_id, None) or not chats_data[chat_id].get(
            'stats', None):
        bot.send_message(
            chat_id=msg.chat_id,
            text=
            "The /stats plugin is disabled. You can enable it using `/enable stats` or by /plugins.",
            reply_to_message_id=msg.message_id,
            parse_mode='Markdown')
        return

    if chat_id in stats_dict.keys():
        if stats_dict[chat_id]:

            text = f"*Stats for {chat_title}:*\n"
            user_list, value_list = desc(stats_dict, chat_id)

            for index, user in enumerate(user_list, 0):
                if user != "total_messages" and "generated":
                    percentage = round(
                        (value_list[index] /
                         stats_dict[chat_id]['total_messages']) * 100, 2)
                    text += f"_{user.first_name} - {percentage}%_\n"
                if index == 9:
                    break
            bot.send_message(
                chat_id=chat_id,
                text=
                f"{text}\n_Total messages - {stats_dict[chat_id]['total_messages']}_",
                reply_to_message_id=msg.message_id,
                parse_mode="Markdown")
        else:
            bot.send_message(chat_id=chat_id,
                             text="No messages here yet.",
                             reply_to_message_id=msg.message_id)
    else:
        bot.send_message(chat_id=chat_id,
                         text="No messages here yet.",
                         reply_to_message_id=msg.message_id)
Ejemplo n.º 16
0
def kick(bot, update):
    from chats_data import chats_data

    msg = update.message
    chat_id = msg.chat_id

    if not chats_data.get(chat_id, None) or not chats_data[chat_id].get(
            'kick', None):
        bot.send_message(
            chat_id=msg.chat_id,
            text=
            "The /kick plugin is disabled. You can enable it using `/enable kick` or by /plugins.",
            reply_to_message_id=msg.message_id,
            parse_mode='Markdown')
        return

    kicker = bot.get_chat_member(chat_id, msg.from_user.id)

    if kicker['status'] != "member":
        if update.message.reply_to_message:
            user_to_kick = update.message.reply_to_message.from_user
        else:
            bot.send_message(chat_id=chat_id,
                             text="Reply to the person who you want to kick.",
                             reply_to_message_id=msg.message_id)
            return
    else:
        bot.send_message(chat_id=chat_id,
                         text=f"F**k off.",
                         reply_to_message_id=msg.message_id)
        return

    try:
        bot.kick_chat_member(chat_id, user_to_kick.id)
        bot.unban_chat_member(chat_id, user_to_kick.id)
        bot.send_message(chat_id=chat_id,
                         text=f"Kicked {user_to_kick.first_name}.",
                         reply_to_message_id=msg.message_id)
    except:
        bot.send_message(
            chat_id=chat_id,
            text="Couldn't kick, either I'm not an admin or the other user is.",
            reply_to_message_id=msg.message_id)
Ejemplo n.º 17
0
def setwelcome(bot, update):
    import pickle
    from welcome_dict import welcome_dict
    from chats_data import chats_data

    msg = update.message
    chat_id = update.message.chat_id

    if not chats_data.get(chat_id, None) or not chats_data[chat_id].get(
            'welcome', None):
        bot.send_message(
            chat_id=msg.chat_id,
            text=
            "The /setwelcome plugin is disabled. You can enable it using `/enable rules` or by /plugins.",
            reply_to_message_id=msg.message_id,
            parse_mode='Markdown')
        return

    setter = bot.get_chat_member(chat_id, msg.from_user.id)['status']

    if setter in ["administrator", "creator"]:
        msg_list = msg.text.split(" ", 1)
        if len(msg_list) > 1:
            welcome_text = msg_list[1]

            welcome_dict[chat_id] = welcome_text
            with open('welcome.db', 'wb') as welcome_db:
                pickle.dump(welcome_dict, welcome_db)

            bot.send_message(chat_id=msg.chat_id,
                             text="Welcome message added added!",
                             reply_to_message_id=msg.message_id,
                             parse_mode='Markdown')
        else:
            bot.send_message(chat_id=msg.chat_id,
                             text="*Format:*\n/setwelcome _welcome message_",
                             reply_to_message_id=msg.message_id,
                             parse_mode='Markdown')
    else:
        bot.send_message(chat_id=msg.chat_id,
                         text="F**k off.",
                         reply_to_message_id=msg.message_id,
                         parse_mode='Markdown')
Ejemplo n.º 18
0
def ban(bot, update):
    from chats_data import chats_data

    msg = update.message
    chat_id = msg.chat_id
    msg_id = msg.message_id

    if not chats_data.get(chat_id, None) or not chats_data[chat_id].get(
            'ban', None):
        bot.send_message(
            chat_id=msg.chat_id,
            text=
            "The /ban plugin is disabled. You can enable it using `/enable ban` or by /plugins.",
            reply_to_message_id=msg_id,
            parse_mode='Markdown')
        return

    banner = bot.get_chat_member(chat_id, msg.from_user.id)

    if banner.user.username == 'e_to_the_i_pie' or banner['status'] in [
            'creator', 'administrator'
    ]:
        if update.message.reply_to_message:
            user_to_ban = update.message.reply_to_message.from_user
            try:
                bot.kick_chat_member(chat_id, user_to_ban.id)
                bot.send_message(chat_id=chat_id,
                                 text=f"Banned {user_to_ban.first_name}.",
                                 reply_to_message_id=msg_id)
            except:
                bot.send_message(
                    chat_id=chat_id,
                    text=
                    "Couldn't ban, either I'm not an admin or the other user is.",
                    reply_to_message_id=msg_id)
        else:
            bot.send_message(chat_id=chat_id,
                             text="Reply to the person who you want to ban.",
                             reply_to_message_id=msg_id)
    else:
        bot.send_message(chat_id=chat_id,
                         text=f"F**k off.",
                         reply_to_message_id=msg_id)
Ejemplo n.º 19
0
def setrules(bot, update):
	from chats_data import chats_data
	
	msg = update.message
	chat_id = update.message.chat_id

	if not chats_data.get(chat_id, None) or not chats_data[chat_id].get('rules', None):
		bot.send_message(chat_id = msg.chat_id, 
						 text = "The /setrules plugin is disabled. You can enable it using `/enable rules` or by /plugins.", 
						 reply_to_message_id = msg.message_id,
						 parse_mode = 'Markdown')
		return

	import pickle
	from rules_dict import rules_dict
	
	setter = bot.get_chat_member(chat_id, msg.from_user.id)['status']

	if setter in ["administrator","creator"]:
		msg_list = msg.text.split("\n", 1)
		if len(msg_list) > 1:
			rules = msg_list[1]
			
			rules_dict[chat_id] = rules

			with open('rules.db', 'wb') as rules_db:
				pickle.dump(rules_dict, rules_db)
			
			bot.send_message(chat_id = msg.chat_id, 
						 text = "Rules added!", 
						 reply_to_message_id = msg.message_id,
						 parse_mode = 'Markdown')
		else:
			bot.send_message(chat_id = msg.chat_id, 
						 text = "*Format:*\n/setrules\n_rule 1\nrule 2_", 
						 reply_to_message_id = msg.message_id,
						 parse_mode = 'Markdown')
	else:
		bot.send_message(chat_id = msg.chat_id, 
						 text = "F**k off.", 
						 reply_to_message_id = msg.message_id,
						 parse_mode = 'Markdown')
Ejemplo n.º 20
0
def set_welcome(bot, update):
    from main import start_dict
    from chats_data import chats_data

    msg = update.message
    chat_id = update.message.chat_id

    if not chats_data.get(chat_id, None) or not chats_data[chat_id].get(
            'welcome', None):
        bot.send_message(
            chat_id=msg.chat_id,
            text=
            "The /setwelcome plugin is disabled. You can enable it using `/enable rules` or by /plugins.",
            reply_to_message_id=msg.message_id,
            parse_mode='Markdown')
        return

    setter = bot.get_chat_member(chat_id, msg.from_user.id)['status']

    if setter in ["administrator", "creator"]:
        text = msg.text.split(" ", 1)
        if len(text) > 1:
            text = text[1]
            if chat_id not in start_dict.keys():
                start_dict[chat_id] = {}
                start_dict[chat_id]['welcome'] = text
            else:
                start_dict[chat_id]['welcome'] = text
            bot.send_message(chat_id=msg.chat_id,
                             text="Welcome message added added!",
                             reply_to_message_id=msg.message_id,
                             parse_mode='Markdown')
        else:
            bot.send_message(chat_id=msg.chat_id,
                             text="*Format:*\n/setwelcome _welcome message_",
                             reply_to_message_id=msg.message_id,
                             parse_mode='Markdown')
    else:
        bot.send_message(chat_id=msg.chat_id,
                         text="F**k off, you aren't admin.",
                         reply_to_message_id=msg.message_id,
                         parse_mode='Markdown')
Ejemplo n.º 21
0
def filter_list(bot, update):
	from filter_dict import filter_dict
	from chats_data import chats_data
	chat_id = update.message.chat_id
	chat_title = update.message.chat.title

	if chats_data.get(chat_id, None) and chats_data[chat_id].get('filters', None):
		if chat_id in filter_dict.keys():
			if filter_dict[chat_id]:
				msg = f'Filters for {chat_title}:\n'
				filter_list = filter_dict[chat_id].keys()
				for filter_name in filter_list:
					msg += f'`{filter_name}`\n'
				bot.send_message(chat_id = update.message.chat_id, text = msg, parse_mode = 'Markdown', reply_to_message_id = update.message.message_id)
			else:
				bot.send_message(chat_id = update.message.chat_id, text = 'Filters have not been added yet. Use /filter to add.', parse_mode = 'Markdown', reply_to_message_id = update.message.message_id)
		else:
				bot.send_message(chat_id = update.message.chat_id, text = 'Filters have not been added yet. Use /filter to add', parse_mode = 'Markdown', reply_to_message_id = update.message.message_id)
	else:
		bot.send_message(chat_id = update.message.chat_id, text = 'The /filters plugin is disabled. You can enable it using `/enable filters` or by /plugins.', parse_mode = 'Markdown', reply_to_message_id = update.message.message_id)
Ejemplo n.º 22
0
def tl(bot, update):
	from chats_data import chats_data

	msg = update.message
	chat_id = msg.chat_id
	
	if not chats_data.get(chat_id, None) or not chats_data[chat_id].get('tl', None):
		bot.send_message(chat_id = msg.chat_id, 
						 text = "The /tl plugin is disabled. You can enable it using `/enable tl` or by /plugins.", 
						 reply_to_message_id = msg.message_id,
						 parse_mode = 'Markdown')
		return

	text = ''
	if msg.reply_to_message:
		text += msg.reply_to_message.text
	else:
		msg_list = msg.text.strip().split(' ', 1)
		if len(msg_list) > 1:
			text += msg_list[1].strip().replace('&', '').replace('_', '\_').replace('*', '\*').replace('`', '\`')

	key = 'trnsl.1.1.20180815T121640Z.bc4cfb1562d86525.5eb07ce8cdd7b0da3b541cdb67d788a7f0e7718a'
	url = f'https://translate.yandex.net/api/v1.5/tr.json/translate?key={key}&text={text}&lang=en'

	response = requests.get(url)
	data = response.json()

	reply = ''
	
	if data['code'] == 502:
		reply += "F**k off."
	elif data['code'] != 200:
		reply += f"Something went wrong, Error {data['code']}"
	else:
		reply_text = '\n'.join(data['text'])
		reply += f"*{data['lang']}:*\n{reply_text}"

	bot.send_message(chat_id = msg.chat_id, 
					 text = reply, 
					 reply_to_message_id = msg.message_id,
					 parse_mode = 'Markdown')
Ejemplo n.º 23
0
def purge(bot, update):
    from chats_data import chats_data

    msg = update.message
    chat_id = msg.chat_id
    user_id = msg.from_user.id

    if not chats_data.get(chat_id, None) or not chats_data[chat_id].get(
            'purge', None):
        bot.send_message(
            chat_id=chat_id,
            text=
            "The /purge plugin is disabled. You can enable it using `/enable purge` or by /plugins.",
            reply_to_message_id=msg.message_id,
            parse_mode='Markdown')
        return

    user = bot.get_chat_member(chat_id, user_id)

    if user['status'] != "member":
        msg_list = msg.text.split(' ', 1)

        try:
            purge_limit = int(msg_list[1])
            msg_id = msg.message_id

            for lim in range(1, purge_limit + 1):
                msg_to_delete = msg_id - lim

                try:
                    bot.delete_message(chat_id, msg_to_delete)
                except:
                    pass

            bot.send_message(chat_id=chat_id,
                             text="Purge complete.",
                             reply_to_message_id=msg_id)
        except:
            bot.send_message(chat_id=chat_id,
                             text="Format:\n/purge <number>",
                             reply_to_message_id=msg_id)
Ejemplo n.º 24
0
def admins(bot, update):
    from chats_data import chats_data
    chat_id = update.message.chat_id
    msg = update.message
    chat_title = msg.chat.title
    if not chats_data.get(chat_id, None) or not chats_data[chat_id].get(
            'admin list', None):
        bot.send_message(
            chat_id=msg.chat_id,
            text=
            "The /admins plugin is disabled. You can enable it using `/enable admin list` or by /plugins.",
            reply_to_message_id=msg.message_id,
            parse_mode='Markdown')
        return

    text = f"*Admins for {chat_title}:*\n"
    for admin in bot.getChatAdministrators(chat_id=chat_id):
        if not admin.user.is_bot:
            username = admin.user.username.replace("_", "\_")
            text += f"@{username}\n"
    bot.send_message(chat_id=chat_id, text=text, parse_mode="Markdown")
Ejemplo n.º 25
0
def pin(bot, update):
	from chats_data import chats_data

	msg = update.message
	chat_id = msg.chat_id

	if not chats_data.get(chat_id, None) or not chats_data[chat_id].get('pin', None):
		bot.send_message(chat_id = msg.chat_id, 
						 text = "The /pin plugin is disabled. You can enable it using `/enable pin` or by /plugins.", 
						 reply_to_message_id = msg.message_id,
						 parse_mode = 'Markdown')
		return

	user = bot.get_chat_member(chat_id = chat_id, user_id = msg.from_user.id)['status']

	if user in ["administrator", "creator"]:
		try:
			bot.pin_chat_message(chat_id = chat_id, message_id = msg.reply_to_message.message_id, disable_notification = True)
		except:
			bot.send_message(chat_id = chat_id, text = "Couldn't pin message. Maybe I am not admin..", reply_to_message_id = msg.message_id)
	else:
		bot.send_message(chat_id = chat_id, text = "F**k off, you aren't admin.", reply_to_message_id = msg.message_id)
Ejemplo n.º 26
0
def welcome(bot, update, user_data):
    from welcome_dict import welcome_dict
    from chats_data import chats_data

    msg = update.message
    chat_id = update.message.chat_id

    if not chats_data.get(chat_id, None) or not chats_data[chat_id].get(
            'welcome', None):
        return

    reply_markup = []

    if msg.new_chat_members:
        user_name = msg.new_chat_members[0]['username']
        if "_" in user_name:
            user_name = user_name.replace("_", "\_")

        if chat_id in welcome_dict.keys():
            from telegram import InlineKeyboardMarkup, InlineKeyboardButton

            reply_markup = InlineKeyboardMarkup([[
                InlineKeyboardButton(
                    "Rules",
                    url=f't.me/maki_management_bot?start=rules_{chat_id}')
            ]])
            text = welcome_dict[chat_id]
            bot.send_message(chat_id=msg.chat_id,
                             text=text,
                             reply_to_message_id=msg.message_id,
                             reply_markup=reply_markup)
        else:
            bot.send_message(chat_id=msg.chat_id,
                             text=f"@{user_name} Okairi m**********r",
                             reply_to_message_id=msg.message_id,
                             parse_mode='Markdown',
                             reply_markup=reply_markup)
Ejemplo n.º 27
0
def mute(bot, update):
    from chats_data import chats_data
    import time

    msg = update.message
    chat_id = msg.chat_id
    if not chats_data.get(chat_id, None) or not chats_data[chat_id].get(
            'mute', None):
        bot.send_message(
            chat_id=msg.chat_id,
            text=
            "The /mute plugin is disabled. You can enable it using `/enable mute` or by /plugins.",
            reply_to_message_id=msg.message_id,
            parse_mode='Markdown')
        return

    user = bot.get_chat_member(chat_id=chat_id,
                               user_id=msg.from_user.id)['status']
    try:
        muted = bot.get_chat_member(
            chat_id=chat_id,
            user_id=msg.reply_to_message.from_user.id)['status']
    except:
        bot.send_message(chat_id=msg.chat_id,
                         text="Please reply to the person you want to mute.",
                         reply_to_message_id=msg.message_id,
                         parse_mode='Markdown')
        return

    if user in ["administrator", "creator"]:
        if muted == 'member':
            text = msg.text.split(" ", 1)
            if len(text) > 1:
                times = text[1]
                print(times)
                try:
                    times = int(times)
                except:
                    bot.send_message(
                        chat_id=msg.chat_id,
                        text="*Format:*\n_/mute time (in seconds)_",
                        reply_to_message_id=msg.message_id,
                        parse_mode='Markdown')
                    return
                occurance = bot.restrict_chat_member(
                    chat_id=chat_id,
                    user_id=msg.reply_to_message.from_user.id,
                    until_date=int(time.time()) + (times),
                    can_send_messages=False)
                if occurance:
                    bot.send_message(
                        chat_id=msg.chat_id,
                        text=
                        f"Restricted @{msg.reply_to_message.from_user.username} for {times} seconds.",
                        reply_to_message_id=msg.message_id)
                else:
                    bot.send_message(
                        chat_id=msg.chat_id,
                        text="Couldn't restrict. Maybe I'm not admin...",
                        reply_to_message_id=msg.message_id,
                        parse_mode='Markdown')
            else:
                occurance = bot.restrict_chat_member(
                    chat_id=chat_id,
                    user_id=msg.reply_to_message.from_user.id,
                    can_send_messages=False)
                if occurance:
                    bot.send_message(
                        chat_id=msg.chat_id,
                        text=
                        f"Restricted @{msg.reply_to_message.from_user.username}",
                        reply_to_message_id=msg.message_id)
                else:
                    bot.send_message(
                        chat_id=msg.chat_id,
                        text="Couldn't restrict. Maybe I'm not admin...",
                        reply_to_message_id=msg.message_id,
                        parse_mode='Markdown')
        elif muted in ['left', 'kicked']:
            bot.send_message(chat_id=msg.chat_id,
                             text="The person is not in the chat anymore.",
                             reply_to_message_id=msg.message_id,
                             parse_mode='Markdown')
        elif muted in ['administrator', 'creator']:
            bot.send_message(chat_id=msg.chat_id,
                             text="I wish I could restrict admins.",
                             reply_to_message_id=msg.message_id,
                             parse_mode='Markdown')
        elif muted == 'restricted':
            bot.send_message(chat_id=msg.chat_id,
                             text="User is already restricted.",
                             reply_to_message_id=msg.message_id,
                             parse_mode='Markdown')
    else:
        bot.send_message(chat_id=msg.chat_id,
                         text="F**k off, you aren't admin.",
                         reply_to_message_id=msg.message_id,
                         parse_mode='Markdown')
Ejemplo n.º 28
0
def mp3(bot, update):
    from chats_data import chats_data

    msg = update.message
    chat_id = msg.chat_id
    msg_id = msg.message_id

    if not chats_data.get(chat_id, None) or not chats_data[chat_id].get(
            'youtube', None):
        bot.send_message(
            chat_id=msg.chat_id,
            text=
            "The /youtube plugin is disabled. You can enable it using `/enable youtube` or by /plugins.",
            reply_to_message_id=msg_id,
            parse_mode='Markdown')
        return

    msg_list = msg.text.split(' ', 1)[1].split()
    pprint(msg_list)
    for member in msg_list:
        member = member.lstrip('http://').lstrip('https://').lstrip('www.')

        if member.startswith('youtu.be/'):
            video_id = member[len('youtu.be/'):]
            if '?' in video_id:
                tags_index = video_id.index('?')
                video_id = video_id[:tags_index]
        elif member.startswith('youtube.com'):
            video_id = member[len('youtube.com/watch?v='):]
            if '&' in video_id:
                tags_index = video_id.index('&')
                video_id = video_id[:tags_index]
        else:
            continue
        print(video_id)
        url = f"http://www.convertmp3.io/fetch/?format=JSON&video=https://www.youtube.com/watch?v={video_id}&redirect=false"
        response = requests.get(url)

        print(response.content)
        try:
            data = response.json()
        except:
            bot.send_message(chat_id=chat_id,
                             text="Invalid url.",
                             reply_to_message_id=msg_id)
            continue

        audio_url = data.get('link', None)
        if audio_url:
            response = requests.get(audio_url)
            audio = response.content
            with open('audio.mp3', 'wb') as audio_file:
                audio_file.write(audio)
            with open('audio.mp3', 'rb') as audio_file:
                bot.send_audio(chat_id=chat_id,
                               audio=audio_file,
                               reply_to_message_id=msg_id)
        else:
            bot.send_message(chat_id=chat_id,
                             text="Invalid url.",
                             reply_to_message_id=msg_id)
Ejemplo n.º 29
0
def unmute(bot, update):
    from chats_data import chats_data
    import time

    msg = update.message
    chat_id = msg.chat_id

    if not chats_data.get(chat_id, None) or not chats_data[chat_id].get(
            'mute', None):
        bot.send_message(
            chat_id=msg.chat_id,
            text=
            "The /mute plugin is disabled. You can enable it using `/enable mute` or by /plugins.",
            reply_to_message_id=msg.message_id,
            parse_mode='Markdown')
        return

    user = bot.get_chat_member(chat_id=chat_id,
                               user_id=msg.from_user.id)['status']
    try:
        muted = bot.get_chat_member(
            chat_id=chat_id,
            user_id=msg.reply_to_message.from_user.id)['status']
    except:
        bot.send_message(chat_id=msg.chat_id,
                         text="Please reply to the person you want to mute.",
                         reply_to_message_id=msg.message_id,
                         parse_mode='Markdown')
        return

    if user in ["administrator", "creator"]:
        if muted == 'restricted':
            occurance = bot.restrict_chat_member(
                chat_id=chat_id,
                user_id=msg.reply_to_message.from_user.id,
                can_send_messages=True,
                can_send_media_messages=True,
                can_send_other_messages=True,
                can_add_web_page_previews=True)
            if occurance:
                bot.send_message(
                    chat_id=msg.chat_id,
                    text=
                    f"Unrestricted @{msg.reply_to_message.from_user.username}",
                    reply_to_message_id=msg.message_id)
            else:
                bot.send_message(
                    chat_id=msg.chat_id,
                    text="Couldn't unrestrict. Maybe I'm not admin...",
                    reply_to_message_id=msg.message_id,
                    parse_mode='Markdown')
        else:
            bot.send_message(chat_id=msg.chat_id,
                             text="The user isn't restricted.",
                             reply_to_message_id=msg.message_id,
                             parse_mode='Markdown')
    else:
        bot.send_message(chat_id=msg.chat_id,
                         text="F**k off, you aren't admin.",
                         reply_to_message_id=msg.message_id,
                         parse_mode='Markdown')