├── runtime.txt ├── Procfile ├── requirements.txt ├── assets ├── logo.png ├── standings-v2.png ├── help-command-v2.png ├── live-league-v2.png ├── invite-command-v2.png ├── league-fixtures-v2.png ├── standings-all-v2.png └── team-fixtures-v2.png ├── .gitignore ├── source ├── logos │ ├── BL.jpg │ ├── PL.jpg │ ├── SA.jpg │ ├── FL1.jpg │ └── SPA.jpg ├── league_code.py ├── exceptions.py ├── league_properties.py ├── team_id.py ├── teamcodes.json ├── bot_commands.py └── utils.py ├── LICENSE ├── bot.py └── README.md /runtime.txt: -------------------------------------------------------------------------------- 1 | python-3.8.3 -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | worker: python bot.py -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.32.0 2 | discord.py==1.3.4 3 | python-dotenv==0.14.0 -------------------------------------------------------------------------------- /assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaheshBharadwaj/Paneka-discord-bot/HEAD/assets/logo.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__/ 2 | team-data.json 3 | team_mapper.py 4 | cache.json 5 | cache/ 6 | test*.py 7 | .env -------------------------------------------------------------------------------- /source/logos/BL.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaheshBharadwaj/Paneka-discord-bot/HEAD/source/logos/BL.jpg -------------------------------------------------------------------------------- /source/logos/PL.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaheshBharadwaj/Paneka-discord-bot/HEAD/source/logos/PL.jpg -------------------------------------------------------------------------------- /source/logos/SA.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaheshBharadwaj/Paneka-discord-bot/HEAD/source/logos/SA.jpg -------------------------------------------------------------------------------- /source/logos/FL1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaheshBharadwaj/Paneka-discord-bot/HEAD/source/logos/FL1.jpg -------------------------------------------------------------------------------- /source/logos/SPA.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaheshBharadwaj/Paneka-discord-bot/HEAD/source/logos/SPA.jpg -------------------------------------------------------------------------------- /assets/standings-v2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaheshBharadwaj/Paneka-discord-bot/HEAD/assets/standings-v2.png -------------------------------------------------------------------------------- /assets/help-command-v2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaheshBharadwaj/Paneka-discord-bot/HEAD/assets/help-command-v2.png -------------------------------------------------------------------------------- /assets/live-league-v2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaheshBharadwaj/Paneka-discord-bot/HEAD/assets/live-league-v2.png -------------------------------------------------------------------------------- /assets/invite-command-v2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaheshBharadwaj/Paneka-discord-bot/HEAD/assets/invite-command-v2.png -------------------------------------------------------------------------------- /assets/league-fixtures-v2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaheshBharadwaj/Paneka-discord-bot/HEAD/assets/league-fixtures-v2.png -------------------------------------------------------------------------------- /assets/standings-all-v2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaheshBharadwaj/Paneka-discord-bot/HEAD/assets/standings-all-v2.png -------------------------------------------------------------------------------- /assets/team-fixtures-v2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaheshBharadwaj/Paneka-discord-bot/HEAD/assets/team-fixtures-v2.png -------------------------------------------------------------------------------- /source/league_code.py: -------------------------------------------------------------------------------- 1 | LEAGUE_CODE = { 2 | "BSA": 2013, #Brazilian First Division 3 | "BL": 2002, #Bundesliga 4 | "FL1": 2015, #Ligue 1 5 | "PL": 2021, #Premier League 6 | "ECL": 2016, #English Championship 7 | "SPA": 2014, #La Liga 8 | "SA": 2019, #Serie A 9 | "PPL": 2017, #Portugese First Dvision 10 | "ERD": 2003, #Eredivisie [Dutch] 11 | "CL": 2001 #Champions League 12 | } -------------------------------------------------------------------------------- /source/exceptions.py: -------------------------------------------------------------------------------- 1 | class InvalidLimitException(Exception): 2 | """ 3 | Invalid number of matches requested 4 | """ 5 | pass 6 | 7 | class InvalidLeagueCodeException(Exception): 8 | """ 9 | The League code requested is either invalid or not supported 10 | """ 11 | pass 12 | 13 | class InvalidTeamCodeException(Exception): 14 | """ 15 | The Team Code requested is invalid 16 | """ 17 | pass 18 | 19 | 20 | -------------------------------------------------------------------------------- /source/league_properties.py: -------------------------------------------------------------------------------- 1 | LEAGUE_PROPERTIES = { 2 | "PL": { 3 | "rl": [18, 20], 4 | "cl": [1, 4], 5 | "el": [5, 5], 6 | }, 7 | "ECL": { 8 | "rl": [21, 24], 9 | "cl": [1, 2], 10 | "el": [3, 6] 11 | }, 12 | 13 | "BL": { 14 | "rl": [16, 18], 15 | "cl": [1, 4], 16 | "el": [5, 6] 17 | }, 18 | 19 | "SPA": { 20 | "rl": [18, 20], 21 | "cl": [1, 3], 22 | "el": [4, 6] 23 | }, 24 | 25 | 26 | "SA": { 27 | "rl": [18, 20], 28 | "cl": [1, 3], 29 | "el": [4, 5] 30 | }, 31 | "PPL": { 32 | "rl": [17, 18], 33 | "cl": [1, 3], 34 | "el": [4, 5] 35 | }, 36 | "FL1": { 37 | "rl": [19, 20], 38 | "cl": [1, 3], 39 | "el": [4, 4] 40 | }, 41 | 42 | "ERD": { 43 | "rl": [16, 18], 44 | "cl": [1, 2], 45 | "el": [3, 3] 46 | }, 47 | "BSA": { 48 | "rl": [16, 20], 49 | "cl": [0, 0], 50 | "el": [0, 0] 51 | } 52 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Mahesh Bharadwaj K 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /source/team_id.py: -------------------------------------------------------------------------------- 1 | TEAM_ID = { 2 | "BAY": "5", 3 | "HSV": "7", 4 | "FCA": "16", 5 | "BSC": "9", 6 | "B04": "3", 7 | "TSG": "2", 8 | "DAR": "55", 9 | "H96": "8", 10 | "M05": "15", 11 | "FCI": "31", 12 | "SVW": "12", 13 | "S04": "6", 14 | "BVB": "4", 15 | "BMG": "18", 16 | "WOB": "11", 17 | "SGE": "19", 18 | "VFB": "10", 19 | "FCK": "1", 20 | "PFC": "1045", 21 | "EVA": "513", 22 | "FCM": "545", 23 | "RCL": "546", 24 | "SUSFC": "356", 25 | "PSV": "674", 26 | "ROM": "100", 27 | "JUVE": "109", 28 | "PAL": "114", 29 | "GEN": "107", 30 | "SASS": "471", 31 | "SSC": "113", 32 | "LAZ": "110", 33 | "INT": "108", 34 | "FCT": "586", 35 | "FIO": "99", 36 | "ACM": "98", 37 | "EMP": "445", 38 | "KAI": "13", 39 | "EBS": "33", 40 | "SVS": "46", 41 | "SCF": "17", 42 | "FCN": "14", 43 | "FSV": "30", 44 | "RBL": "721", 45 | "GRE": "21", 46 | "KAR": "32", 47 | "HEI": "44", 48 | "1860": "26", 49 | "PAD": "29", 50 | "VFL": "36", 51 | "FCP": "503", 52 | "FCU": "28", 53 | "FOR": "24", 54 | "MUFC": "66", 55 | "THFC": "73", 56 | "AFCB": "1044", 57 | "AVFC": "58", 58 | "EFC": "62", 59 | "WAT": "346", 60 | "LCFC": "338", 61 | "SUN": "71", 62 | "NCFC": "68", 63 | "CRY": "354", 64 | "CFC": "61", 65 | "SWA": "72", 66 | "NUFC": "67", 67 | "SFC": "340", 68 | "AFC": "57", 69 | "WHU": "563", 70 | "SCFC": "70", 71 | "LFC": "64", 72 | "WBA": "74", 73 | "MCFC": "65", 74 | "MFF": "749", 75 | "ASTA": "1056", 76 | "GSK": "610", 77 | "CSK": "751", 78 | "SHA": "724", 79 | "ZEN": "731", 80 | "DYK": "842", 81 | "MTA": "971", 82 | "OLA": "654", 83 | "DIN": "755", 84 | "AUE": "22", 85 | "VFR": "50", 86 | "OSC": "521", 87 | "PSG": "524", 88 | "MAR": "516", 89 | "SMC": "514", 90 | "NIC": "522", 91 | "MON": "548", 92 | "NAN": "543", 93 | "GUI": "538", 94 | "MHSC": "518", 95 | "SCB": "536", 96 | "REN": "529", 97 | "BOR": "526", 98 | "REI": "547", 99 | "TOU": "511", 100 | "ETI": "527", 101 | "OLY": "523", 102 | "LOR": "525", 103 | "CFE": "285", 104 | "UDA": "267", 105 | "CCF": "295", 106 | "LAC": "560", 107 | "RSS": "92", 108 | "ESP": "80", 109 | "FCG": "82", 110 | "ATM": "78", 111 | "RAY": "87", 112 | "VAL": "95", 113 | "MAL": "84", 114 | "SEV": "559", 115 | "BIL": "77", 116 | "FCB": "81", 117 | "MAD": "86", 118 | "LUD": "88", 119 | "VIG": "558", 120 | "BET": "90", 121 | "VCF": "94", 122 | "GCF": "83", 123 | "EIB": "278", 124 | "SCP": "498", 125 | "SLB": "495" 126 | } -------------------------------------------------------------------------------- /source/teamcodes.json: -------------------------------------------------------------------------------- 1 | { 2 | "FC Bayern M\u00fcnchen": "BAY", 3 | "Hamburger SV": "HSV", 4 | "FC Augsburg": "FCA", 5 | "Hertha BSC": "BSC", 6 | "Bayer Leverkusen": "B04", 7 | "TSG 1899 Hoffenheim": "TSG", 8 | "SV Darmstadt 98": "DAR", 9 | "Hannover 96": "H96", 10 | "1. FSV Mainz 05": "M05", 11 | "FC Ingolstadt 04": "FCI", 12 | "Werder Bremen": "SVW", 13 | "FC Schalke 04": "S04", 14 | "Borussia Dortmund": "BVB", 15 | "Bor. M\u00f6nchengladbach": "BMG", 16 | "VfL Wolfsburg": "WOB", 17 | "Eintracht Frankfurt": "SGE", 18 | "VfB Stuttgart": "VFB", 19 | "1. FC K\u00f6ln": "FCK", 20 | "Paris FC": "PFC", 21 | "\u00c9vian Thonon Gaillard FC": "EVA", 22 | "FC Metz": "FCM", 23 | "RC Lens": "RCL", 24 | "Sheffield United FC": "SUSFC", 25 | "PSV Eindhoven": "PSV", 26 | "AS Roma": "ROM", 27 | "Juventus Turin": "JUVE", 28 | "US Citt\u00e1 di Palermo": "PAL", 29 | "Genoa CFC": "GEN", 30 | "US Sassuolo Calcio": "SASS", 31 | "SSC Napoli": "SSC", 32 | "SS Lazio": "LAZ", 33 | "FC Internazionale Milano": "INT", 34 | "Torino FC": "FCT", 35 | "ACF Fiorentina": "FIO", 36 | "AC Milan": "ACM", 37 | "Empoli FC": "EMP", 38 | "1. FC Kaiserslautern": "KAI", 39 | "Eintracht Braunschweig": "EBS", 40 | "SV Sandhausen": "SVS", 41 | "SC Freiburg": "SCF", 42 | "1. FC N\u00fcrnberg": "FCN", 43 | "FSV Frankfurt": "FSV", 44 | "Red Bull Leipzig": "RBL", 45 | "SpVgg Greuther F\u00fcrth": "GRE", 46 | "Karlsruher SC": "KAR", 47 | "1. FC Heidenheim 1846": "HEI", 48 | "TSV 1860 M\u00fcnchen": "1860", 49 | "SC Paderborn 07": "PAD", 50 | "VfL Bochum": "VFL", 51 | "FC St. Pauli": "FCP", 52 | "1. FC Union Berlin": "FCU", 53 | "Fortuna D\u00fcsseldorf": "FOR", 54 | "Manchester United FC": "MUFC", 55 | "Tottenham Hotspur FC": "THFC", 56 | "AFC Bournemouth": "AFCB", 57 | "Aston Villa FC": "AVFC", 58 | "Everton FC": "EFC", 59 | "Watford FC": "WAT", 60 | "Leicester City FC": "LCFC", 61 | "Sunderland AFC": "SUN", 62 | "Norwich City FC": "NCFC", 63 | "Crystal Palace FC": "CRY", 64 | "Chelsea FC": "CFC", 65 | "Swansea City FC": "SWA", 66 | "Newcastle United FC": "NUFC", 67 | "Southampton FC": "SFC", 68 | "Arsenal FC": "AFC", 69 | "West Ham United FC": "WHU", 70 | "Stoke City FC": "SCFC", 71 | "Liverpool FC": "LFC", 72 | "West Bromwich Albion FC": "WBA", 73 | "Manchester City FC": "MCFC", 74 | "Malm\u00f6 FF": "MFF", 75 | "FC Astana": "ASTA", 76 | "Galatasaray SK": "GSK", 77 | "CSKA Moscow": "CSK", 78 | "Shakhtar Donetsk": "SHA", 79 | "FC Zenit St. Petersburg": "ZEN", 80 | "Dynamo Kyiv": "DYK", 81 | "Maccabi Tel Aviv": "MTA", 82 | "Olympiacos F.C.": "OLA", 83 | "GNK Dinamo Zagreb": "DIN", 84 | "Erzgebirge Aue": "AUE", 85 | "VfR Aalen": "VFR", 86 | "OSC Lille": "OSC", 87 | "Paris Saint-Germain": "PSG", 88 | "Olympique de Marseille": "MAR", 89 | "SM Caen": "SMC", 90 | "OGC Nice": "NIC", 91 | "AS Monaco FC": "MON", 92 | "FC Nantes": "NAN", 93 | "EA Guingamp": "GUI", 94 | "Montpellier H\u00e9rault SC": "MHSC", 95 | "SC Bastia": "SCB", 96 | "Stade Rennais FC": "REN", 97 | "FC Girondins de Bordeaux": "BOR", 98 | "Stade de Reims": "REI", 99 | "Toulouse FC": "TOU", 100 | "AS Saint-\u00c9tienne": "ETI", 101 | "Olympique Lyonnais": "OLY", 102 | "FC Lorient": "LOR", 103 | "Elche FC": "CFE", 104 | "UD Almeria": "UDA", 105 | "C\u00f3rdoba CF": "CCF", 106 | "RC Deportivo La Coruna": "LAC", 107 | "Real Sociedad de F\u00fatbol": "RSS", 108 | "RCD Espanyol": "ESP", 109 | "Getafe CF": "FCG", 110 | "Club Atl\u00e9tico de Madrid": "ATM", 111 | "Rayo Vallecano de Madrid": "RAY", 112 | "Valencia CF": "VAL", 113 | "M\u00e1laga CF": "MAL", 114 | "Sevilla FC": "SEV", 115 | "Athletic Club": "BIL", 116 | "FC Barcelona": "FCB", 117 | "Real Madrid CF": "MAD", 118 | "Levante UD": "LUD", 119 | "RC Celta de Vigo": "VIG", 120 | "Real Betis": "BET", 121 | "Villarreal CF": "VCF", 122 | "Granada CF": "GCF", 123 | "SD Eibar": "EIB", 124 | "Sporting CP": "SCP", 125 | "FC Porto": "FCP", 126 | "SL Benfica": "SLB" 127 | } -------------------------------------------------------------------------------- /bot.py: -------------------------------------------------------------------------------- 1 | # bot.py 2 | import os 3 | import random 4 | 5 | import source.bot_commands as bot_commands 6 | 7 | import discord 8 | from discord.ext import commands 9 | from dotenv import load_dotenv 10 | from source.utils import fetchImage 11 | 12 | load_dotenv('.env') 13 | TOKEN = os.getenv('DISCORD_TOKEN') 14 | 15 | bot = commands.Bot(command_prefix='.') 16 | bot.remove_command('help') 17 | 18 | 19 | @bot.event 20 | async def on_ready(): 21 | print("Bot Running!") 22 | await bot.change_presence( 23 | activity=discord.Activity( 24 | type=discord.ActivityType.listening, 25 | name=".help on " + str(len(bot.guilds)) + " server(s)") 26 | ) 27 | 28 | 29 | @bot.event 30 | async def on_guild_join(guild): 31 | for channel in guild.text_channels: 32 | if channel.permissions_for(guild.me).send_messages: 33 | helpEmbed = bot_commands.getHelpEmbed() 34 | await channel.send('Hey There! Just got added to this channel!\ 35 | \nBasic commands are listed below :)', embed=helpEmbed) 36 | break 37 | 38 | 39 | @bot.command(name='99', help='Responds with a random quote from Brooklyn 99') 40 | async def nine_nine(ctx): 41 | brooklyn_99_quotes = [ 42 | 'I\'m the human form of the 💯 emoji.', 43 | 'Bingpot!', 44 | 'Cool. Cool cool cool cool cool cool cool,\ 45 | \nno doubt no doubt no doubt no doubt.', 46 | 'If I die, turn my tweets into a book', 47 | 'Captain Wuntch. Good to see you. But if you’re here, who’s guarding Hades?', 48 | 'Anyone over the age of six celebrating a birthday should go to hell.' 49 | ] 50 | 51 | response = random.choice(brooklyn_99_quotes) 52 | await ctx.send(response) 53 | 54 | # Requires admin 55 | @bot.command(name='update') 56 | async def update(ctx, message = None): 57 | if ctx.message.author.id == 694128831291981844: 58 | for guild in bot.guilds: 59 | for channel in guild.text_channels: 60 | if channel.permissions_for(guild.me).send_messages: 61 | helpEmbed = bot_commands.getHelpEmbed() 62 | await channel.send(message, embed=helpEmbed) 63 | break 64 | 65 | 66 | @bot.command(name='standings-all', help='Displays standings with all details') 67 | async def standingsAll(ctx, arg=''): 68 | text = bot_commands.getStandings(arg.upper(), mode='all') 69 | if text is not None: 70 | await ctx.send(text) 71 | else: 72 | leagueCodeEmbed = bot_commands.getLeagueCodes( 73 | 'Invalid League Code Entered!') 74 | await ctx.send(embed=leagueCodeEmbed) 75 | 76 | 77 | @bot.command(name='standings', help='Display Standings with only Matches played & points') 78 | async def standings(ctx, arg=''): 79 | text = bot_commands.getStandings(arg.upper(), mode='long') 80 | if text is not None: 81 | await ctx.send(text) 82 | else: 83 | leagueCodeEmbed = bot_commands.getLeagueCodes( 84 | 'Invalid League Code Entered!') 85 | await ctx.send(embed=leagueCodeEmbed) 86 | 87 | 88 | @bot.command(name='fixtures', alias=['matches', 'm', 'f']) 89 | async def fixtures(ctx, code = '', limit=5): 90 | fixturesEmbed = bot_commands.getFixtures(code.upper(), limit) 91 | fixturesEmbed.set_footer(text='Requested By: ' + str(ctx.author)) 92 | 93 | path = fetchImage(code.upper()) 94 | if path is not None: 95 | fixturesEmbed.set_thumbnail(url='attachment://image.jpg') 96 | await ctx.send(embed=fixturesEmbed, file=discord.File(path, 'image.jpg')) 97 | else: 98 | await ctx.send(embed=fixturesEmbed) 99 | 100 | @bot.command(name='live', aliases=['l']) 101 | async def matches(ctx, code='', limit=5): 102 | liveMatchesEmbed = bot_commands.getMatches(code.upper(), limit) 103 | liveMatchesEmbed.set_footer(text='Requested By: ' + str(ctx.author)) 104 | 105 | path = fetchImage(code.upper()) 106 | if path is not None: 107 | liveMatchesEmbed.set_thumbnail(url='attachment://image.jpg') 108 | await ctx.send(embed=liveMatchesEmbed, file=discord.File(path, 'image.jpg')) 109 | else: 110 | await ctx.send(embed=liveMatchesEmbed) 111 | 112 | @bot.command(name='league-codes') 113 | async def leagueCodes(ctx): 114 | leagueCodesEmbed = bot_commands.getLeagueCodes() 115 | leagueCodesEmbed.set_footer(text='Requested By: ' + str(ctx.author)) 116 | await ctx.send(embed=leagueCodesEmbed) 117 | 118 | @bot.command(name='team-codes') 119 | async def teamCodes(ctx): 120 | teamCodesEmbed = bot_commands.getTeamCodes() 121 | teamCodesEmbed.set_footer(text='Requested By: ' + str(ctx.author)) 122 | await ctx.send(embed=teamCodesEmbed) 123 | 124 | @bot.command(name='invite') 125 | async def invite(ctx): 126 | inviteEmbed = bot_commands.getInviteEmbed(ctx) 127 | await ctx.author.send(embed=inviteEmbed) 128 | await ctx.send(f'The invite link has been sent to your DM {ctx.author.mention} :D') 129 | 130 | @bot.command(name='help') 131 | async def help(ctx): 132 | helpEmbed = bot_commands.getHelpEmbed(ctx) 133 | await ctx.send(embed=helpEmbed) 134 | 135 | bot.run(TOKEN) -------------------------------------------------------------------------------- /source/bot_commands.py: -------------------------------------------------------------------------------- 1 | import discord 2 | import requests 3 | import json 4 | import os 5 | 6 | from dotenv import load_dotenv 7 | from source.utils import putTableAll, putTableLong, putFixtures, fetchJSON, putMatches 8 | from source.league_code import LEAGUE_CODE 9 | from source.team_id import TEAM_ID 10 | from source.exceptions import * 11 | 12 | 13 | def getStandings(code, mode='long'): 14 | """ 15 | Function that delivers standings in text format. 16 | Queries the cache for the requested data, if not found, 17 | Loads the data from API and caches it 18 | 19 | Parameters: 20 | ----------- 21 | code: str 22 | The ID of the league for which standings are required 23 | mode: 'long' or 'all', optional 24 | * defaults to 'long' 25 | * 'long' -> SNO, Team name, Matches Played, Points Obtained 26 | * 'all' -> SNO, Team Code, Matches Played, Won, Drawn, Lost, Pts, Goal Difference 27 | 28 | Returns: 29 | -------- 30 | str 31 | standings if code is valid, or an error message 32 | 33 | """ 34 | 35 | try: 36 | if code not in LEAGUE_CODE: 37 | raise InvalidLeagueCodeException 38 | 39 | obj = fetchJSON(code, 'standings') 40 | if mode == 'all': 41 | return putTableAll(obj) 42 | return putTableLong(obj) 43 | 44 | except InvalidLeagueCodeException: 45 | return None 46 | 47 | 48 | def getFixtures(code, limit: int): 49 | """ 50 | Displays the fixtures in the requested league / team as an embed 51 | Fetches fixtures from JSON file and renders embed for it, 52 | Displays 'limit' matches 53 | 54 | Parameters: 55 | ----------- 56 | code: str 57 | The ID of the league or team for which fixtures are required 58 | limit: int, optional 59 | Number of fixtures to display (default value of 5) 60 | 61 | Returns: 62 | -------- 63 | discord.Embed 64 | Shows the fixtures as many as requested, 65 | Incase of invalid code, relevant help embed is returned 66 | 67 | """ 68 | try: 69 | if limit < 0: 70 | raise InvalidLimitException 71 | 72 | mode = 'league' 73 | if code not in LEAGUE_CODE: 74 | if code in TEAM_ID: 75 | mode = 'team' 76 | else: 77 | return discord.Embed(title='Please enter a valid code!', 78 | description='Please Refer to **.team-codes** for team codes\ 79 | \nAnd **.league-codes** for league-codes', 80 | color=0xf58300) 81 | 82 | obj = fetchJSON(code, 'fixtures') 83 | return putFixtures(obj, code, limit, mode) 84 | 85 | except InvalidLimitException: 86 | return discord.Embed(title='Limit must be greater than :zero:', 87 | description="Enter a valid limit :smile:", 88 | color=0xf58300) 89 | 90 | 91 | def getMatches(code, limit: int): 92 | try: 93 | if limit < 0: 94 | raise InvalidLimitException 95 | 96 | mode = 'league' 97 | if code not in LEAGUE_CODE: 98 | if code in TEAM_ID: 99 | mode = 'team' 100 | else: 101 | return discord.Embed(title='Please enter a valid code!', 102 | description='Please Refer to **.team-codes** for team codes\ 103 | \nAnd **.league-codes** for league-codes', 104 | color=0xf58300) 105 | 106 | obj = fetchJSON(code, 'live') 107 | return putMatches(obj, code, limit, mode) 108 | 109 | except InvalidLimitException: 110 | return discord.Embed(title='Limit must be greater than :zero:', 111 | description="Enter a valid limit :smile:", 112 | color=0xf58300) 113 | 114 | 115 | def getLeagueCodes(title="League Codes"): 116 | """ 117 | Returns Leagues and their codes as an Embed 118 | 119 | Parameters: 120 | ----------- 121 | title: str, optional 122 | Title of the embed (by default: "League Codes") 123 | 124 | Returns: 125 | -------- 126 | discord.Embed 127 | Embed displaying league codes 128 | 129 | """ 130 | 131 | embed = discord.Embed( 132 | title=title, 133 | description="Refer codes for Top :five: Leagues here:", 134 | color=0xf58300) 135 | embed.add_field(name=':one: Premier League', 136 | value='PL' + "\n\u200b", inline=False) 137 | embed.add_field(name=':two: La Liga', value='SPA' + 138 | "\n\u200b", inline=True) 139 | embed.add_field(name=':three: Serie A', value='SA' + 140 | "\n\u200b", inline=False) 141 | embed.add_field(name=':four: Bundesliga', 142 | value='BA' + "\n\u200b", inline=True) 143 | embed.add_field(name=':five:Ligue 1', value='FL1', inline=False) 144 | embed.add_field(name='For more leagues', 145 | value='click [Here](https://github.com/MaheshBharadwaj/paneka/blob/master/README.md/#league-codes)') 146 | return embed 147 | 148 | 149 | def getTeamCodes(title="Team Codes"): 150 | """ 151 | Returns Teams and their codes as an Embed 152 | 153 | Parameters: 154 | ----------- 155 | title: str, optional 156 | Title of the embed (by default: "Team Codes") 157 | 158 | Returns: 159 | -------- 160 | discord.Embed 161 | Embed displaying team codes 162 | 163 | """ 164 | 165 | embed = discord.Embed( 166 | title=title, 167 | description="Refer codes for Top :one: :zero: Teams here:", 168 | color=0xf58300) 169 | embed.add_field(name='Real Madrid', value='MAD' + "\n\u200b", inline=True) 170 | embed.add_field(name='FC Barcelona', value='FCB' + "\n\u200b", inline=True) 171 | embed.add_field(name='Manchester United', 172 | value='MUFC' + "\n\u200b", inline=True) 173 | embed.add_field(name='Arsenal', value='AFC' + "\n\u200b", inline=True) 174 | embed.add_field(name='Bayern Munich', value='BAY' + 175 | "\n\u200b", inline=True) 176 | embed.add_field(name='Chelsea', value='CFC' + "\n\u200b", inline=True) 177 | embed.add_field(name='Juventus', value='JUVE' + "\n\u200b", inline=True) 178 | embed.add_field(name='Atletico Madrid', 179 | value='ATM' + "\n\u200b", inline=True) 180 | embed.add_field(name='Liverpool', value='LFC' + "\n\u200b", inline=True) 181 | embed.add_field(name='Manche$ter City', value='MCFC', inline=True) 182 | return embed 183 | 184 | 185 | def getInviteEmbed(ctx): 186 | """ 187 | Generates Invite embed to invite bot 188 | 189 | Parameters: 190 | ----------- 191 | ctx: discord.Context 192 | Context data passed by discord when a command is invoked 193 | 194 | Returns: 195 | -------- 196 | discord.Embed 197 | Showing invite URL for the bot 198 | 199 | """ 200 | inviteEmbed = discord.Embed( 201 | title='Invite link!', 202 | description='URL for inviting bot to your servers' 203 | ) 204 | 205 | inviteEmbed.add_field( 206 | name=":warning: You need to be an admin to add bots :slight_smile:", 207 | value="https://discord.com/api/oauth2/authorize?client_id=731544990446256198&permissions=60416&scope=bot" 208 | ) 209 | 210 | return inviteEmbed 211 | 212 | 213 | def getHelpEmbed(ctx=None): 214 | """ 215 | Generates the 'Help' embed when requested 216 | 217 | Parameters: 218 | ----------- 219 | ctx: discord.Context 220 | Context data passed by discord when a command is invoked 221 | 222 | Returns: 223 | -------- 224 | discord.Embed 225 | Showing help data for the commands available 226 | 227 | """ 228 | embed = discord.Embed( 229 | title="Paneka-Help!", 230 | description="Shows available commands and their functions\ 231 | \nNOTE: The command prefix is '.'", 232 | color=0xf58300) 233 | embed.set_thumbnail( 234 | url="https://img.icons8.com/fluent/144/000000/get-help.png") 235 | embed.add_field(name=":one: .standings-all [league code]", inline=False, 236 | value="Detailed Standings, with team codes") 237 | embed.add_field(name=":two: .standings [league code]", inline=False, 238 | value="Display Standings") 239 | embed.add_field(name=":three: .fixtures [league code or team code] [limit (default: :five: )]", inline=False, 240 | value="Displays fixtures of matches of the league or team",) 241 | embed.add_field(name=":four: .live [league code or team code] [limit (default: :five: )]", inline=False, 242 | value='Display Live Matches of the league or team') 243 | embed.add_field(name=":five: .league-codes", inline=False, 244 | value="Displays Leagues and their Respective Codes") 245 | embed.add_field(name=":six: .team-codes", inline=False, 246 | value="Displayes Teams and their Respective Codes") 247 | embed.add_field(name=":seven: .invite", inline=False, 248 | value="Invite bot to your servers!") 249 | embed.add_field( 250 | name="\u200b", value=":computer: Link to GitHub Repository: [Click Here](https://github.com/MaheshBharadwaj/paneka)", inline=False) 251 | embed.add_field( 252 | name="\u200b", value=":shield: Link to Support Server: [Discord Invite](https://discord.gg/DXPgJaMsZe)", inline=False 253 | ) 254 | if ctx is not None: 255 | embed.set_footer(text='Requested By: ' + str(ctx.author)) 256 | 257 | return embed 258 | 259 | 260 | if __name__ == "__main__": 261 | print(getStandings('PL')) 262 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

3 |
4 |
5 |
6 |
7 |
23 |
24 |
32 |
33 |
41 |
42 |
54 |
55 |
60 |
61 |
71 |
72 |
80 |
81 |