Exemple #1
0
                            d = {
                                'player_id': man['id'],
                                'name': man['name'],
                                'team': arg_team_name,
                                'position': man['position'],
                                'dob': man['dateOfBirth'],
                                'born_in': man['countryOfBirth'],
                                'nationality': man['nationality'],
                                'shirt_no': man['shirtNumber'],
                                'role': 'player'
                            }
                            DATA.append(d)

                            SQUAD += man['name'] + '\n'

                    Player.insert_many(DATA).on_conflict('replace').execute()

                    RESULT_MSG = f'*{team_a["name"]}* ({team_a["tla"]})\nFounded: _{team_a["founded"]}_\nStadium: _{team_a["venue"]}_\n\n' \
                                 f'_{team_a["address"]}_\n\nPhone: _{team_a["phone"]}_\nWebsite: _{team_a["website"]}_\nEmail: _{team_a["email"]}_\n\n' \
                                 f'{SQUAD}'

            except DoesNotExist:
                RESULT_MSG = "Can't find team."

    context.bot.send_message(update.effective_chat.id,
                             RESULT_MSG,
                             parse_mode="MARKDOWN")


dp.add_handler(CommandHandler('team', team))
Exemple #2
0
    elif 'live' in query.data:
        LIVE = []
        comp = FGM.find_comp(query.data.replace('live', ''))
        match_data = FGM.read_data()
        EDIT_MSG = 'No live matches in ' + comp
        for match in match_data:
            if match['status'] == 'IN_PLAY' and str(
                    match['comp']) == query.data.replace('live', ''):
                LIVE.append(match)

        if LIVE:
            EDIT_MSG = f'*Live {comp} matches*\n'
            for match in LIVE:
                EDIT_MSG += '---\n*' \
                            + match['homeTeam']['name'] \
                            + '* _' + str(match['score']['fullTime']['homeTeam']) \
                            + '_ vs _' \
                            + str(match['score']['fullTime']['awayTeam']) \
                            + '_ *' \
                            + match['awayTeam']['name'] \
                            + '*\n'

    context.bot.edit_message_text(text=EDIT_MSG,
                                  chat_id=query.message.chat_id,
                                  message_id=query.message.message_id,
                                  parse_mode='MARKDOWN')


dp.add_handler(CallbackQueryHandler(button))
Exemple #3
0

@run_async
def live(update, context):
    LIVE = []
    COMPS = []
    LIVE_MSG = 'No live matches! Use /recent or /upcoming to get match list'
    match_data = FGM.read_data()
    for match in match_data:
        if match['status'] == 'IN_PLAY':
            if match['comp'] not in COMPS:
                COMPS.append(match['comp'])
            LIVE.append(match)

    if LIVE:
        LIVE_MSG = 'Select below to get live scores\n'

    KEYBOARD = []

    for comp in COMPS:
        but = [InlineKeyboardButton(FGM.find_comp(str(comp)), callback_data='live' + str(comp))]
        KEYBOARD.append(but)

    REPLY_MARKUP = InlineKeyboardMarkup(KEYBOARD)

    context.bot.send_message(update.effective_chat.id, LIVE_MSG,
                             parse_mode="MARKDOWN", reply_markup=REPLY_MARKUP)


dp.add_handler(CommandHandler('live', live, filters=Filters.private))
Exemple #4
0
                       team=team).on_conflict('replace').execute()
            SUB_MSG = f'Added {team} to sub list'
            break
        else:
            SUB_MSG = f'Can not find {team} in /live matches'

    return SUB_MSG


@run_async
def sub(update, context):
    SUB_MSG = 'Syntax is `/sub <team>`'
    if context.args:
        team = ' '.join(context.args)
        if update.effective_chat.type == 'private':
            SUB_MSG = add_to_sub(update, team)

        else:
            if update.effective_chat.all_members_are_administrators \
                    or update.effective_user.id in get_admin_ids(context.bot, update.effective_chat.id):
                SUB_MSG = add_to_sub(update, team)
            else:
                SUB_MSG = 'Admin only command!'

    context.bot.send_message(update.effective_chat.id,
                             SUB_MSG,
                             parse_mode="MARKDOWN")


dp.add_handler(CommandHandler('sub', sub))
Exemple #5
0
@run_async
def live(update, context):
    COMPS = []
    LIVE_MSG = 'No live matches! Use /recent or /upcoming to get match list'
    match_data = Live.select()
    for match in match_data:
        if match.league not in COMPS and ('UTC' not in match.time and 'FT' not in match.time):
            COMPS.append(match.league)

    if COMPS:
        LIVE_MSG = 'Select below to get live scores\n'

    KEYBOARD = []

    for comp in COMPS:
        but = [InlineKeyboardButton(comp, callback_data='live' + comp)]
        KEYBOARD.append(but)

    REPLY_MARKUP = InlineKeyboardMarkup(KEYBOARD)
    REPLY_MARKUP_MAIN = ReplyKeyboardMarkup(
        [[KeyboardButton(x) for x in KEY_BUTTONS]], resize_keyboard=True)

    context.bot.send_message(update.effective_chat.id,
                             '_Some competions may not be supported due to pricing issues (service provider)_', parse_mode='MARKDOWN', reply_markup=REPLY_MARKUP_MAIN)
    context.bot.send_message(update.effective_chat.id, LIVE_MSG,
                             parse_mode="MARKDOWN", reply_markup=REPLY_MARKUP)


dp.add_handler(CommandHandler('live', live, filters=Filters.private))
dp.add_handler(MessageHandler(Filters.private & Filters.regex(r'Live'), live))
        match_date = datetime.datetime.strptime(match['utcDate'],
                                                '%Y-%m-%dT%H:%M:%SZ')
        time_diff = match_date - datetime.datetime.utcnow()
        if -1 < time_diff.days < 3:
            if match['status'] == 'SCHEDULED':
                if match['comp'] not in COMPS:
                    COMPS.append(match['comp'])
                SCHEDULED.append(match)

    if SCHEDULED:
        SCHEDULED_MSG = 'Choose below to see upcoming matches\n'

    KEYBOARD = []

    for comp in COMPS:
        but = [
            InlineKeyboardButton(FGM.find_comp(str(comp)),
                                 callback_data='upcoming' + str(comp))
        ]
        KEYBOARD.append(but)

    REPLY_MARKUP = InlineKeyboardMarkup(KEYBOARD)

    context.bot.send_message(update.effective_chat.id,
                             SCHEDULED_MSG,
                             parse_mode="MARKDOWN",
                             reply_markup=REPLY_MARKUP)


dp.add_handler(CommandHandler('upcoming', upcoming, filters=Filters.private))
Exemple #7
0
        match_date = datetime.datetime.strptime(match.date_utc,
                                                '%Y-%m-%dT%H:%M:%SZ')
        time_diff = match_date - datetime.datetime.utcnow()
        if -1 < time_diff.days < 3:
            if match.comp not in COMPS:
                COMPS.append(match.comp)

    if COMPS:
        SCHEDULED_MSG = 'Choose below to see upcoming matches\n'

    KEYBOARD = []

    for comp in COMPS:
        but = [
            InlineKeyboardButton(FGM.find_comp(comp),
                                 callback_data='upcoming' + str(comp))
        ]
        KEYBOARD.append(but)

    REPLY_MARKUP = InlineKeyboardMarkup(KEYBOARD)

    context.bot.send_message(update.effective_chat.id,
                             SCHEDULED_MSG,
                             parse_mode="MARKDOWN",
                             reply_markup=REPLY_MARKUP)


dp.add_handler(CommandHandler('upcoming', upcoming, filters=Filters.private))
dp.add_handler(
    MessageHandler(Filters.private & Filters.regex(r'Upcoming'), upcoming))
Exemple #8
0
def recent(update, context):
    FINISHED = []
    COMPS = []
    FINISHED_MSG = 'No Recent Matches'
    match_data = FGM.read_data()
    for match in match_data:
        match_date = datetime.datetime.strptime(match['utcDate'], '%Y-%m-%dT%H:%M:%SZ')
        time_diff = match_date - datetime.datetime.utcnow()
        if -4 < time_diff.days < 0:
            if match['status'] == 'FINISHED':
                if match['comp'] not in COMPS:
                    COMPS.append(match['comp'])
                FINISHED.append(match)

    if FINISHED:
        FINISHED_MSG = 'Select below to get recent matches\n'

    KEYBOARD = []

    for comp in COMPS:
        but = [InlineKeyboardButton(FGM.find_comp(str(comp)), callback_data='recent' + str(comp))]
        KEYBOARD.append(but)

    REPLY_MARKUP = InlineKeyboardMarkup(KEYBOARD)

    context.bot.send_message(update.effective_chat.id, FINISHED_MSG,
                             parse_mode="MARKDOWN", reply_markup=REPLY_MARKUP)


dp.add_handler(CommandHandler('recent', recent, filters=Filters.private))
Exemple #9
0
from telegram.ext import CommandHandler, run_async
from telegram.ext import Filters

from FootGramBot import dp


@run_async
def start(update, context):

    START_MSG = '''
Hello there! I'm bot written in python by @ssiyad . Please pass any feedback to him!

If you'r interested in my source code, it is available at https://github.com/ssiyad/FootGramBot

You can get some help by using `/help` command.

Please help me evolve and keep #Love #Football ;)'''

    context.bot.send_message(chat_id=update.effective_chat.id,
                             text=START_MSG,
                             parse_mode='MARKDOWN')


dp.add_handler(CommandHandler('start', start, filters=Filters.private))
Exemple #10
0
from telegram.ext import CommandHandler

from FootGramBot import dp


def show_help(update, context):
    HELP_MSG = '''
Hello! How can I help you?

`/start`:       Start the bot
`/recent`:      Get recent matches with scores
`/live`:        Get live matches with scores
`/upcoming`:    Get upcoming fixtures

Group Commands:
`Coming Soon!`'''

    context.bot.send_message(update.effective_chat.id,
                             HELP_MSG,
                             parse_mode="MARKDOWN")


dp.add_handler(CommandHandler('help', show_help))
Exemple #11
0
                              + result.away \
                              + '*\n'

        if LIVE:
            if FINISHED or SCHEDULED:
                SEARCH_MSG += f'---\n\nLive matches\n'
            else:
                SEARCH_MSG += f'Live matches\n'
            for result in LIVE:
                SEARCH_MSG += '---\n_' \
                              + str(result.time) \
                              + '_ *' \
                              + result.home \
                              + '* _' \
                              + str(result.goals_home) \
                              + '_ vs _' \
                              + str(result.goals_away) \
                              + '_ *' \
                              + result.away \
                              + '*\n'

    else:
        SEARCH_MSG = 'Err!'

    context.bot.send_message(update.effective_chat.id,
                             SEARCH_MSG,
                             parse_mode="MARKDOWN")


dp.add_handler(CommandHandler('match', search_match))
Exemple #12
0
        match_date = datetime.datetime.strptime(match.date_utc,
                                                '%Y-%m-%dT%H:%M:%SZ')
        time_diff = match_date - datetime.datetime.utcnow()
        if -4 < time_diff.days < 0:
            if match.comp not in COMPS:
                COMPS.append(match.comp)

    if COMPS:
        FINISHED_MSG = 'Select below to get recent matches\n'

    KEYBOARD = []

    for comp in COMPS:
        but = [
            InlineKeyboardButton(FGM.find_comp(comp),
                                 callback_data='recent' + str(comp))
        ]
        KEYBOARD.append(but)

    REPLY_MARKUP = InlineKeyboardMarkup(KEYBOARD)

    context.bot.send_message(update.effective_chat.id,
                             FINISHED_MSG,
                             parse_mode="MARKDOWN",
                             reply_markup=REPLY_MARKUP)


dp.add_handler(CommandHandler('recent', recent, filters=Filters.private))
dp.add_handler(
    MessageHandler(Filters.private & Filters.regex(r'Recent'), recent))