├── Procfile ├── requirements.txt ├── README.md ├── LICENSE └── main.py /Procfile: -------------------------------------------------------------------------------- 1 | worker: python3 main.py 2 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pyrogram 2 | tgcrypto 3 | countryinfo 4 | python-dotenv 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Country Information Bot 2 | A country information finder telegram bot 3 | 4 | --- 5 | 6 | ## Variables 7 | 8 | - `API_HASH` Your API Hash from my.telegram.org 9 | - `API_ID` Your API ID from my.telegram.org 10 | - `BOT_TOKEN` Your bot token from @BotFather 11 | 12 | --- 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Fayas 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 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import os 2 | import urllib 3 | from dotenv import load_dotenv 4 | from countryinfo import CountryInfo 5 | from pyrogram import Client, filters 6 | from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton 7 | 8 | 9 | load_dotenv() 10 | 11 | Bot = Client( 12 | "Country-Info-Bot", 13 | bot_token = os.environ["BOT_TOKEN"], 14 | api_id = int(os.environ["API_ID"]), 15 | api_hash = os.environ["API_HASH"] 16 | ) 17 | 18 | START_TEXT = """Hello {}, 19 | 20 | I am a country information finder bot. \ 21 | Give me a country name I will send the informations of the country.""" 22 | 23 | HELP_TEXT = """**More Help** 24 | 25 | - Just send me a country name 26 | - Then I will check and send you the informations 27 | 28 | **Informations :-** 29 | Name, Native Name, Capital, Population, Region, Sub Region, \ 30 | Top Level Domains, Calling Codes, Currencies, Residence, \ 31 | Timezone, Wikipedia, Google""" 32 | 33 | ABOUT_TEXT = """**About Me** 34 | 35 | - **Bot :** `Country Info Bot` 36 | - **Creator :** 37 | - [Telegram](https://telegram.me/FayasNoushad) 38 | - [GitHub](https://github.com/FayasNoushad) 39 | - **Source :** [Click here](https://github.com/FayasNoushad/Country-Info-Bot/tree/main) 40 | - **Language :** [Python3](https://python.org) 41 | - **Framework :** [Pyrogram](https://pyrogram.org)""" 42 | 43 | START_BUTTONS = InlineKeyboardMarkup( 44 | [ 45 | [ 46 | InlineKeyboardButton('Send Feedback', url='https://telegram.me/FayasNoushad') 47 | ], 48 | [ 49 | InlineKeyboardButton('Help', callback_data='help'), 50 | InlineKeyboardButton('About', callback_data='about'), 51 | InlineKeyboardButton('Close', callback_data='close') 52 | ] 53 | ] 54 | ) 55 | HELP_BUTTONS = InlineKeyboardMarkup( 56 | [ 57 | [ 58 | InlineKeyboardButton('Home', callback_data='home'), 59 | InlineKeyboardButton('About', callback_data='about'), 60 | InlineKeyboardButton('Close', callback_data='close') 61 | ] 62 | ] 63 | ) 64 | ABOUT_BUTTONS = InlineKeyboardMarkup( 65 | [ 66 | [ 67 | InlineKeyboardButton('Home', callback_data='home'), 68 | InlineKeyboardButton('Help', callback_data='help'), 69 | InlineKeyboardButton('Close', callback_data='close') 70 | ] 71 | ] 72 | ) 73 | ERROR_BUTTON = InlineKeyboardMarkup( 74 | [ 75 | [ 76 | InlineKeyboardButton('Help', callback_data='help'), 77 | InlineKeyboardButton('Close', callback_data='close') 78 | ] 79 | ] 80 | ) 81 | 82 | 83 | @Bot.on_callback_query() 84 | async def cb_data(bot, update): 85 | 86 | if update.data == "home": 87 | await update.message.edit_text( 88 | text=START_TEXT.format(update.from_user.mention), 89 | reply_markup=START_BUTTONS, 90 | disable_web_page_preview=True 91 | ) 92 | 93 | elif update.data == "help": 94 | await update.message.edit_text( 95 | text=HELP_TEXT, 96 | reply_markup=HELP_BUTTONS, 97 | disable_web_page_preview=True 98 | ) 99 | 100 | elif update.data == "about": 101 | await update.message.edit_text( 102 | text=ABOUT_TEXT, 103 | reply_markup=ABOUT_BUTTONS, 104 | disable_web_page_preview=True 105 | ) 106 | 107 | else: 108 | await update.message.delete() 109 | 110 | 111 | @Bot.on_message(filters.private & filters.command(["start"])) 112 | async def start(bot, update): 113 | 114 | await update.reply_text( 115 | text=START_TEXT.format(update.from_user.mention), 116 | disable_web_page_preview=True, 117 | reply_markup=START_BUTTONS 118 | ) 119 | 120 | 121 | @Bot.on_message(filters.private & filters.text) 122 | async def countryinfo(bot, update): 123 | 124 | try: 125 | country = CountryInfo(update.text) 126 | except KeyError: 127 | await update.reply_text( 128 | text="Key error.\nCan you check the name again." 129 | ) 130 | return 131 | 132 | google_url = "https://www.google.com/search?q="+urllib.parse.quote(country.name()) 133 | info = f"""**Country Information** 134 | 135 | Name : `{country.name()}` 136 | Native Name : `{country.native_name()}` 137 | Capital : `{country.capital()}` 138 | Population : `{country.population()}` 139 | Region : `{country.region()}` 140 | Sub Region : `{country.subregion()}` 141 | Top Level Domains : `{country.tld()}` 142 | Calling Codes : `{country.calling_codes()}` 143 | Currencies : `{country.currencies()}` 144 | Residence : `{country.demonym()}` 145 | Timezone : `{country.timezones()}`""" 146 | 147 | reply_markup=InlineKeyboardMarkup( 148 | [ 149 | [ 150 | InlineKeyboardButton('Wikipedia', url=country.wiki()), 151 | InlineKeyboardButton('Google', url=google_url) 152 | ], 153 | [ 154 | InlineKeyboardButton('Send Feedback', url='https://telegram.me/FayasNoushad') 155 | ] 156 | ] 157 | ) 158 | 159 | try: 160 | await update.reply_text( 161 | text=info, 162 | reply_markup=reply_markup, 163 | disable_web_page_preview=True 164 | ) 165 | except Exception as error: 166 | print(error) 167 | 168 | 169 | Bot.run() 170 | --------------------------------------------------------------------------------