本文整理汇总了Python中telepot.glance函数的典型用法代码示例。如果您正苦于以下问题:Python glance函数的具体用法?Python glance怎么用?Python glance使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了glance函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: handle
def handle(msg):
flavor = telepot.flavor(msg)
# normal message
if flavor == "normal":
content_type, chat_type, chat_id = telepot.glance(msg)
print "Normal Message:", content_type, chat_type, chat_id
# Do your stuff according to `content_type` ...
# inline query - need `/setinline`
elif flavor == "inline_query":
query_id, from_id, query_string = telepot.glance(msg, flavor=flavor)
print "Inline Query:", query_id, from_id, query_string
# Compose your own answers
articles = [{"type": "article", "id": "abc", "title": "ABC", "message_text": "Good morning"}]
bot.answerInlineQuery(query_id, articles)
# chosen inline result - need `/setinlinefeedback`
elif flavor == "chosen_inline_result":
result_id, from_id, query_string = telepot.glance(msg, flavor=flavor)
print "Chosen Inline Result:", result_id, from_id, query_string
# Remember the chosen answer to do better next time
else:
raise telepot.BadFlavor(msg)
开发者ID:salejovg,项目名称:telepot,代码行数:29,代码来源:webhook_flask_skeleton.py
示例2: handle_msg
def handle_msg(msg):
flavor = telepot.flavor(msg)
# print(flavor)
pprint(msg)
if flavor == "normal":
content_type, chat_type, chat_id = telepot.glance(msg, flavor)
if content_type != "text":
return
msgText = msg["text"].strip()
for plugin in arconfig.plugins:
scan = scanRegex(plugin.regex, msgText)
if scan is not None:
ans = plugin.handler(bot, scan, msg, flavor)
if ans is not None:
bot.sendMessage(chat_id, ans, reply_to_message_id=msg["message_id"], parse_mode="Markdown",
disable_web_page_preview=False)
# print(content_type, chat_type, chat_id)
elif flavor == "inline_query":
query_id, from_id, query_string = telepot.glance(msg, flavor)
for plugin in arconfig.plugins:
groups = scanRegex(plugin.regexInline, query_string)
if groups:
ans = plugin.handler(bot, groups, msg, flavor)
if ans is not None:
bot.answerInlineQuery(query_id, ans)
开发者ID:AstonishedByTheLackOfCake,项目名称:arcueidbot,代码行数:26,代码来源:bot.py
示例3: handle
def handle(msg):
flavor = telepot.flavor(msg)
if flavor == 'normal':
bot.sendMessage(chat_id,"Ok")
print 'Normal message'
elif flavor == 'inline_query':
query_id, from_id, query_string = telepot.glance(msg, flavor='inline_query')
print from_id
if len(query_string)>=3:
filelist=find(query_string)
#print filelist
articles=[]
id=0
for filename in filelist:
articles.append(InlineQueryResultArticle(id=filename, title=os.path.splitext(filename)[0], message_text=os.path.splitext(filename)[0]))
id+=1
print articles
bot.answerInlineQuery(query_id, articles)
elif flavor == 'chosen_inline_result':
print "chosen_inline_result"
result_id, from_id, query_string = telepot.glance(msg, flavor='chosen_inline_result')
print result_id
print from_id
f = open("mp3/"+ result_id, 'rb')
#bot.sendDocument(from_id,f)
bot.sendMessage(from_id,"Ok")
开发者ID:tanzilli,项目名称:TanzoLab,代码行数:31,代码来源:inline.py
示例4: handle
def handle(msg):
flavor = telepot.flavor(msg)
# normal message
if flavor == 'normal':
content_type, chat_type, chat_id = telepot.glance(msg)
print 'Normal Message:', content_type, chat_type, chat_id
# Do your stuff according to `content_type` ...
# inline query - need `/setinline`
elif flavor == 'inline_query':
query_id, from_id, query_string = telepot.glance(msg, flavor=flavor)
print 'Inline Query:', query_id, from_id, query_string
# Compose your own answers
articles = [{'type': 'article',
'id': 'abc', 'title': 'ABC', 'message_text': 'Good morning'}]
bot.answerInlineQuery(query_id, articles)
# chosen inline result - need `/setinlinefeedback`
elif flavor == 'chosen_inline_result':
result_id, from_id, query_string = telepot.glance(msg, flavor=flavor)
print 'Chosen Inline Result:', result_id, from_id, query_string
# Remember the chosen answer to do better next time
else:
raise telepot.BadFlavor(msg)
开发者ID:salejovg,项目名称:telepot,代码行数:30,代码来源:skeleton.py
示例5: handle
def handle(msg):
flavor = telepot.flavor(msg)
# normal message
if flavor == 'normal':
content_type, chat_type, chat_id = telepot.glance(msg)
print 'Normal Message:', content_type, chat_type, chat_id,
content = msg['text']
if containsKeyword(content):
bot.sendMessage(chat_id, content)
responseImg = random.choice(os.listdir("./Images/"))
responsefile = open("./Images/" + responseImg, 'rb')
bot.sendPhoto(chat_id, responsefile)
# Do your stuff according to `content_type` ...
# inline query - need `/setinline`
elif flavor == 'inline_query':
query_id, from_id, query_string = telepot.glance(msg, flavor=flavor)
print 'Inline Query:', query_id, from_id, query_string
# Compose your own answers
articles = [{'type': 'article',
'id': 'abc', 'title': 'ABC', 'message_text': 'Good morning'}]
bot.answerInlineQuery(query_id, articles)
# chosen inline result - need `/setinlinefeedback`
elif flavor == 'chosen_inline_result':
result_id, from_id, query_string = telepot.glance(msg, flavor=flavor)
print 'Chosen Inline Result:', result_id, from_id, query_string
# Remember the chosen answer to do better next time
else:
raise telepot.BadFlavor(msg)
开发者ID:misleadingTitle,项目名称:ProvaBot,代码行数:35,代码来源:MembroBot.py
示例6: handle
def handle(self, msg):
if 'migrate_to_chat_id' in msg:
yield from self.onSupergroupUpgradeCallback(self, msg)
else:
flavor = telepot.flavor(msg)
if flavor == "chat": # chat message
content_type, chat_type, chat_id = telepot.glance(msg)
if content_type == 'text':
if TelegramBot.is_command(msg): # bot command
cmd, params = TelegramBot.parse_command(msg['text'])
user_id = TelegramBot.get_user_id(msg)
args = {'params': params, 'user_id': user_id, 'chat_type': chat_type}
if cmd in self.commands:
yield from self.commands[cmd](self, chat_id, args)
else:
if self.config['be_quiet']:
pass
else:
yield from self.sendMessage(chat_id, "Unknown command: {cmd}".format(cmd=cmd))
elif TelegramBot.is_blacklisted_word(self, msg['text']):
pass
else: # plain text message
yield from self.onMessageCallback(self, chat_id, msg)
elif content_type == 'location':
yield from self.onLocationShareCallback(self, chat_id, msg)
elif content_type == 'new_chat_member':
yield from self.onUserJoinCallback(self, chat_id, msg)
elif content_type == 'left_chat_member':
yield from self.onUserLeaveCallback(self, chat_id, msg)
elif content_type == 'photo':
yield from self.onPhotoCallback(self, chat_id, msg)
elif content_type == 'sticker':
if 'enable_sticker_sync' in tg_bot.ho_bot.config.get_by_path(['telesync']):
if tg_bot.ho_bot.config.get_by_path(['telesync'])['enable_sticker_sync']:
yield from self.onStickerCallback(self, chat_id, msg)
elif flavor == "inline_query": # inline query e.g. "@gif cute panda"
query_id, from_id, query_string = telepot.glance(msg, flavor=flavor)
print("inline_query")
elif flavor == "chosen_inline_result":
result_id, from_id, query_string = telepot.glance(msg, flavor=flavor)
print("chosen_inline_result")
else:
raise telepot.BadFlavor(msg)
开发者ID:fortiZde,项目名称:hangoutsbot,代码行数:56,代码来源:__init__.py
示例7: handle
async def handle(self, msg):
flavor = telepot.flavor(msg)
if flavor == 'normal':
content_type, chat_type, chat_id = telepot.glance(msg, flavor)
server_logger.info("Normal %s message, %s." % (content_type, chat_id))
await bot.sendMessage(int(chat_id), "I'm an inline bot. You cannot speak to me directly")
elif flavor == 'inline_query':
msg_id, from_id, query_string = telepot.glance(msg, flavor='inline_query')
server_logger.info("Inline equation, %s : %s" % (from_id, query_string))
answerer.answer(msg)
开发者ID:bmagyarkuti,项目名称:inlinelatex,代码行数:10,代码来源:inlinetexbot.py
示例8: handle
def handle(blob):
flavor = telepot.flavor(blob)
if flavor == 'chat':
content_type, chat_type, chat_id = telepot.glance(blob)
print (content_type, chat_type, chat_id)
if content_type == 'text':
smartReply(blob['text'], blob['from']['id'])
elif flavor == 'inline_query':
query_id, from_id, query_string = telepot.glance(blob, flavor='inline_query')
print ('Inline query:', query_id, from_id, query_string)
pprint(blob)
开发者ID:rakshakhegde,项目名称:kyddo-hack,代码行数:11,代码来源:telepot-kyddo.py
示例9: on_chat_message
def on_chat_message(self, msg):
try:
flavor = telepot.flavor(msg)
# inline query test code...
# Have to answer inline query to receive chosen result
log.info('flavor : %s', flavor)
if flavor == 'inline_query':
log.info('inline query!!')
query_id, from_id, query_string = telepot.glance(msg, flavor=flavor)
log.info('Inline Query: id:%s, from:%d, msg:%s', query_id, from_id, query_string)
articles = [{'type': 'article',
'id': 'abc', 'title': 'ABC', 'message_text': 'Good morning'}]
self.bot.answerInlineQuery(query_id, articles)
return
content_type, chat_type, chat_id = telepot.glance(msg)
log.info("ContentType : '%s'", content_type)
log.info("chat_type : '%s'", chat_type)
log.info("chat_id : %d", chat_id)
# Message to Log Write
self.PrintMsg(msg)
# Valid User Check
if not chat_id in self.valid_user:
log.info("Invalid user : %d", chat_id)
return
log.debug("chat_type:'%s'", chat_type)
if chat_type == 'group':
groupMsg = self.group_command_handler(unicode(msg['text']), chat_id)
log.info("Group Message : %s", groupMsg)
return
if content_type is 'text':
self.command_handler(unicode(msg['text']), chat_id)
log.info(msg['text'])
return
if content_type is 'document':
file_name = msg['document']['file_name']
file_id = msg['document']['file_id']
file_ext = os.path.splitext(file_name)
file_type = msg['document']['mime_type']
self.file_handler(file_name, file_id, file_ext[1], file_type, chat_id)
return
except Exception, e:
log.error(e, exc_info=True)
开发者ID:ludishur,项目名称:xpebot,代码行数:53,代码来源:BotManager.py
示例10: handle
def handle(self, msg):
flavor = telepot.flavor(msg)
msg_text = ""
articles = [{'type': 'article',
'id': 'abc', 'title': 'ABC', 'message_text': 'Good morning'}]
# normal message
if flavor == 'normal':
content_type, chat_type, chat_id = telepot.glance(msg)
try:
# msg_data = json.loads(msg)
if (len(msg)):
msg_text = msg["text"]
cmdArray = string.rsplit(msg_text,' ')
command = cmdArray[0]
if (len(command)):
print ("command: "+command)
if (command == "/getdevvals"):
ssn_cmd = '===ssn10001000502003b{"ssn":{"v":1,"obj":1,"cmd":"getdevvals", "data": {"g":1}}}968f'
self.sendSsnCommand(msg = ssn_cmd, obj_id = 1)
except Exception as ex:
print("Cannot decode JSON object, msg={}: {}".format(msg,ex))
print('Normal Message:', content_type, chat_type, chat_id)
self.bot.sendMessage(chat_id, msg_text)
# show_keyboard = {'keyboard': [['Yes','No'], ['Maybe','Maybe not']]}
# bot.sendMessage('-123873656', 'This is a custom keyboard', reply_markup=show_keyboard)
# inline query - need `/setinline`
elif flavor == 'inline_query':
query_id, from_id, query_string = telepot.glance(msg, flavor=flavor)
print('Inline Query:', query_id, from_id, query_string)
self.bot.answerInlineQuery(query_id, articles)
# Do your stuff according to `content_type` ...
# chosen inline result - need `/setinlinefeedback`
elif flavor == 'chosen_inline_result':
result_id, from_id, query_string = telepot.glance(msg, flavor=flavor)
print('Chosen Inline Result:', result_id, from_id, query_string)
# Remember the chosen answer to do better next time
else:
raise telepot.BadFlavor(msg)
# Compose your own answers
print (msg)
开发者ID:lireric,项目名称:ssnproxy2,代码行数:49,代码来源:ssntelegram.py
示例11: handle
def handle(self, msg):
if "migrate_to_chat_id" in msg:
yield from self.onSupergroupUpgradeCallback(self, msg)
else:
flavor = telepot.flavor(msg)
if flavor == "chat": # chat message
content_type, chat_type, chat_id = telepot.glance(msg)
if content_type == "text":
if TelegramBot.is_command(msg): # bot command
cmd, params = TelegramBot.parse_command(msg["text"])
user_id = TelegramBot.get_user_id(msg)
args = {"params": params, "user_id": user_id, "chat_type": chat_type}
if cmd in self.commands:
yield from self.commands[cmd](self, chat_id, args, cmd)
else:
if self.config["be_quiet"]:
pass
else:
yield from self.sendMessage(chat_id, "Unknown command: {cmd}".format(cmd=cmd))
else: # plain text message
yield from self.onMessageCallback(self, chat_id, msg)
elif content_type == "location":
yield from self.onLocationShareCallback(self, chat_id, msg)
elif content_type == "new_chat_member":
yield from self.onUserJoinCallback(self, chat_id, msg)
elif content_type == "left_chat_member":
yield from self.onUserLeaveCallback(self, chat_id, msg)
elif content_type == "photo":
yield from self.onPhotoCallback(self, chat_id, msg)
elif flavor == "inline_query": # inline query e.g. "@gif cute panda"
query_id, from_id, query_string = telepot.glance(msg, flavor=flavor)
print("inline_query")
elif flavor == "chosen_inline_result":
result_id, from_id, query_string = telepot.glance(msg, flavor=flavor)
print("chosen_inline_result")
else:
raise telepot.BadFlavor(msg)
开发者ID:MTRNord,项目名称:hangoutsbot,代码行数:48,代码来源:__init__.py
示例12: on_message
def on_message(self, msg):
flavor = telepot.flavor(msg)
if flavor == 'inline_query':
query_id, from_id, query_string = telepot.glance(msg, flavor=flavor)
print(self.id, ':', 'Inline Query:', query_id, from_id, query_string)
articles = [{'type': 'article',
'id': 'abc', 'title': 'ABC', 'message_text': 'Good morning'}]
self.bot.answerInlineQuery(query_id, articles)
print(self.id, ':', 'Answers sent.')
elif flavor == 'chosen_inline_result':
result_id, from_id, query_string = telepot.glance(msg, flavor=flavor)
print(self.id, ':', 'Chosen Inline Result:', result_id, from_id, query_string)
开发者ID:salejovg,项目名称:telepot,代码行数:16,代码来源:inline.py
示例13: compute_answer
def compute_answer():
query_id, from_id, query_string = telepot.glance(msg, flavor='inline_query')
print('Computing for: %s' % query_string)
articles = [{'type': 'article',
'id': 'abc', 'title': query_string, 'message_text': query_string}]
return articles
开发者ID:Garmahis666,项目名称:telepot,代码行数:7,代码来源:skeletona_route.py
示例14: handle
def handle(msg):
welcome="welcome!\nwith this bot u can downloder any yuotube video in mp3 format.\ncan u get me a youtube url and file name?"
benvenuto = "ciao\n con questo bot puoi scaricare video da yt in formato mp3. iviami il link yt + il nome file\nNON SI ACCETTANO SPAZI!"
content_type, chat_type, chat_id, = telepot.glance(msg)
print (msg)
with open('/home/makerfra/Documents/yt_bot/log/log.txt', 'w') as infile:
infile.write(str(msg))
if content_type == 'text':
cmd = msg['text'].split()
if cmd[0] == '/start':
bot.sendMessage(chat_id, welcome)
bot.sendMessage(chat_id, benvenuto)
else:
yt_opts['outtmpl'] = path + cmd[1]+".mp3"
try:
with yt.YoutubeDL(yt_opts) as ydl:
ydl.download([cmd[0]])
bot.sendAudio(chat_id, open(path + cmd[1]+".mp3", 'rb'))
print("send file...")
os.remove(path+cmd[1]+'.mp3')
print("file deleded...")
except Exception as error:
bot.sendMessage(chat_id, "error...")
print(error)
开发者ID:MakerFra,项目名称:YouTube_dlBOT,代码行数:28,代码来源:Bot.py
示例15: msg_cb
def msg_cb(self, msg):
content_type, chat_type, chat_id = telepot.glance(msg)
print("content_type, chat_type, chat_id", content_type, chat_type, chat_id)
k = telegram.Keyboard()
if content_type == 'location':
print("location", msg['location'])
k.hide_keyboard()
self.bot.sendMessage(chat_id, **k.get_message_params("Got it!"))
elif content_type == 'text' and "
|
请发表评论