-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRangeBrandBot.py
75 lines (48 loc) · 2.06 KB
/
RangeBrandBot.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from telegram.ext import Updater
updater = Updater(token='328623928:AAGiz2ZHVM2yDYe68Lo0w_3pF-JQHXtYtsI')
dispatcher = updater.dispatcher
import logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
# Start Command
def start(bot, update):
bot.sendMessage(
chat_id = update.message.chat_id,
pars_mode ='HTML',
text = 'رنگبرند یک لیست از برندهای مطرح در ایران (چه ایرانی، چه خارجی) است. \n'
'در این لیست، کد رنگهای رسمی برندها برای طراحان وب فارسی و یا طراحان گرافیک آماده شده. \n '
'منابع رنگبرند رو دانلود کنید /download \n'
'یا اینکه نام برند مد نظر را نوشته تا کد یا رو در اختیارتون بزاریم.',
)
from telegram.ext import CommandHandler, MessageHandler, Filters
start_handler = CommandHandler('start', start)
dispatcher.add_handler(start_handler)
updater.start_polling()
# Download Command - download RangeBrand Zip file
def download(bot,update):
bot.sendDocument(
chat_id = update.message.chat_id,
document = 'https://github.com/IKAcc/RangeBrand/archive/master.zip',
caption = 'فایل زیپ شده رنگ برند',)
download_handler = CommandHandler('download', download)
dispatcher.add_handler(download_handler)
import json
from pprint import pprint
def color(bot, update,args):
with open('rangeBrand.json') as request_brand:
colors = json.load(request_brand)
colors_list = colors[args]["colors"]
colors_result = ' '.join(colors_list)
bot.sendMessage(
chat_id = update.message.chat_id,
text = colors_result,
)
color_handler = CommandHandler('color', color, pass_args = True)
dispatcher.add_handler(color_handler)
# Unknown color name
def unknown(bot, update):
bot.sendMessage(
chat_id = update.message.chat_id,
text = 'نام وارد شده معتبر نیست',
)
unknown_handler = MessageHandler(Filters.command, unknown)
dispatcher.add_handler(unknown_handler)