-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
31 lines (24 loc) · 791 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import telebot
from udpy import UrbanClient
import os
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('TOKEN')
bot = telebot.TeleBot(TOKEN)
client = UrbanClient()
def remove_char(line):
'''removes square brackets surrounding words for a cleaner look'''
line=line.replace('[','')
line=line.replace(']','')
return line
def get_def(term):
'''returns definition of term'''
defs = client.get_definition(term) # list of definitions
return remove_char(defs[0].definition)
@bot.message_handler(commands=['start', 'help'])
def start(message):
bot.reply_to(message, "just type the word you want to look up")
@bot.message_handler(func=lambda message: True)
def definition(message):
bot.reply_to(message, get_def(message.text))
bot.infinity_polling()