本文整理汇总了Python中telepot.glance2函数的典型用法代码示例。如果您正苦于以下问题:Python glance2函数的具体用法?Python glance2怎么用?Python glance2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了glance2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
def handle(msg):
flavor = telepot.flavor(msg)
# normal message
if flavor == "normal":
content_type, chat_type, chat_id = telepot.glance2(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.glance2(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"}]
yield from bot.answerInlineQuery(query_id, articles)
# chosen inline result - need `/setinlinefeedback`
elif flavor == "chosen_inline_result":
result_id, from_id, query_string = telepot.glance2(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)
示例2: handle
def handle(msg):
flavor = telepot.flavor(msg)
# a normal message
if flavor == 'normal':
content_type, chat_type, chat_id = telepot.glance2(msg)
print content_type, chat_type, chat_id
# Do your stuff according to `content_type` ...
# an inline query - only AFTER `/setinline` has been done for the bot.
elif flavor == 'inline_query':
query_id, from_id, query_string = telepot.glance2(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)
# a chosen inline result - only AFTER `/setinlinefeedback` has been done for the bot.
elif flavor == 'chosen_inline_result':
result_id, from_id, query_string = telepot.glance2(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)
示例3: handle
def handle(self, msg):
flavor = telepot.flavor(msg)
# normal message
if flavor == 'normal':
content_type, chat_type, chat_id = telepot.glance2(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.glance2(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.glance2(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)
示例4: answer
def answer(msg):
flavor = telepot.flavor(msg)
if flavor == "inline_query":
query_id, from_id, query = telepot.glance2(msg, flavor=flavor)
if from_id != USER_ID:
print "Unauthorized user:", from_id
return
examine(msg, "InlineQuery")
articles = [
InlineQueryResultArticle(
id="abc", title="HK", message_text="Hong Kong", url="https://www.google.com", hide_url=True
),
{"type": "article", "id": "def", "title": "SZ", "message_text": "Shenzhen", "url": "https://www.yahoo.com"},
]
photos = [
InlineQueryResultPhoto(
id="123",
photo_url="https://core.telegram.org/file/811140934/1/tbDSLHSaijc/fdcc7b6d5fb3354adf",
thumb_url="https://core.telegram.org/file/811140934/1/tbDSLHSaijc/fdcc7b6d5fb3354adf",
),
{
"type": "photo",
"id": "345",
"photo_url": "https://core.telegram.org/file/811140184/1/5YJxx-rostA/ad3f74094485fb97bd",
"thumb_url": "https://core.telegram.org/file/811140184/1/5YJxx-rostA/ad3f74094485fb97bd",
"caption": "Caption",
"title": "Title",
"message_text": "Message Text",
},
]
results = random.choice([articles, photos])
bot.answerInlineQuery(query_id, results)
elif flavor == "chosen_inline_result":
result_id, from_id, query = telepot.glance2(msg, flavor=flavor)
if from_id != USER_ID:
print "Unauthorized user:", from_id
return
examine(msg, "ChosenInlineResult")
print "Chosen inline query:"
pprint.pprint(msg)
else:
raise telepot.BadFlavor(msg)
示例5: handle
def handle(self, msg):
flavor = telepot.flavor(msg)
# a normal message
if flavor == 'normal':
content_type, chat_type, chat_id = telepot.glance2(msg)
print(content_type, chat_type, chat_id)
# Do your stuff according to `content_type` ...
# an inline query - possible only AFTER `/setinline` has been done for the bot.
elif flavor == 'inline_query':
query_id, from_id, query_string = telepot.glance2(msg, flavor=flavor)
print(query_id, from_id, query_string)
示例6: handle
def handle(msg):
flavor = telepot.flavor(msg)
# normal message
if flavor == 'normal':
content_type, chat_type, chat_id = telepot.glance2(msg)
print('Normal Message:', content_type, chat_type, chat_id)
command = msg['text']
if command == '/start':
start(chat_id)
elif command == '/eagles':
news_command_handler(chat_id, 'eagles')
elif command == '/flyers':
news_command_handler(chat_id, 'flyers')
elif command == '/sixers':
news_command_handler(chat_id, 'sixers')
elif command == '/phillies':
news_command_handler(chat_id, 'phillies')
elif command == '/help':
help(chat_id)
elif command == '/settings':
settings(chat_id)
else:
unknown(chat_id)
return('Message sent')
# Do your stuff according to `content_type` ...
# inline query - need `/setinline`
elif flavor == 'inline_query':
query_id, from_id, query_string = telepot.glance2(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.glance2(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)
示例7: see_every_content_types
def see_every_content_types(msg):
global expected_content_type, content_type_iterator
flavor = telepot.flavor(msg)
if flavor == "normal":
content_type, chat_type, chat_id = telepot.glance2(msg)
from_id = msg["from"]["id"]
if chat_id != USER_ID and from_id != USER_ID:
print "Unauthorized user:", chat_id, from_id
return
examine(msg, "Message")
try:
if content_type == expected_content_type:
expected_content_type = content_type_iterator.next()
bot.sendMessage(chat_id, "Please give me a %s." % expected_content_type)
else:
bot.sendMessage(
chat_id,
"It is not a %s. Please give me a %s, please." % (expected_content_type, expected_content_type),
)
except StopIteration:
# reply to sender because I am kicked from group already
bot.sendMessage(from_id, "Thank you. I am done.")
else:
raise telepot.BadFlavor(msg)
示例8: handle
def handle(msg):
content_type, chat_type, chat_id = telepot.glance2(msg)
m = telepot.namedtuple.namedtuple(msg, 'Message')
if chat_id < 0:
# group message
logger.info('Received a %s from %s, by %s' % (content_type, m.chat, m.from_))
else:
# private message
logger.info('Received a %s from %s' % (content_type, m.chat)) # m.chat == m.from_
if content_type == 'text':
if msg['text'] == '/start':
yield from bot.sendMessage(chat_id, # Welcome message
"You send me an Emoji"
"\nI give you the Unicode"
"\n\nOn Python 2, remember to prepend a 'u' to unicode strings,"
"e.g. \U0001f604 is u'\\U0001f604'")
return
reply = ''
# For long messages, only return the first 10 characters.
if len(msg['text']) > 10:
reply = 'First 10 characters:\n'
# Length-checking and substring-extraction may work differently
# depending on Python versions and platforms. See above.
reply += msg['text'][:10].encode('unicode-escape').decode('ascii')
logger.info('>>> %s', reply)
yield from bot.sendMessage(chat_id, reply)
示例9: handle
def handle(msg):
global user_state
# pprint.pprint(msg)
content_type, chat_type, chat_id = telepot.glance2(msg)
validUser = False
# Only respond valid users
for user in user_ids:
if chat_id == user:
validUser = True
if validUser == False:
return
# Ignore non-text message
if content_type != 'text':
return
command = msg['text'].strip().lower().split()
if command[0] == '/start':
showMainKeyboard(chat_id, user_state)
elif command[0] == '/close':
hide_keyboard = {'hide_keyboard': True}
bot.sendMessage(chat_id, 'Closing light control', reply_markup=hide_keyboard)
else:
lights(chat_id, command[0])
示例10: on_message
def on_message(self, msg):
content_type, chat_type, chat_id = telepot.glance2(msg)
if content_type != 'text':
self.sender.sendMessage('Give me two numbers, please.')
return
try:
m = msg['text'].strip().split()
m1 = int(m[0])
m2 = int(m[1])
if len(m) > 2:
raise ValueError
except :
self.sender.sendMessage('Give two numbers correctly, please.')
return
# check the guess against the answer ...
if m1 * m2 != self._answer:
# give a descriptive hint
hint = self._hint(self._answer, m1, m2)
self.sender.sendMessage(hint)
else:
self.sender.sendMessage('Correct!')
self.close()
示例11: insertBirthday
def insertBirthday(msg):
# Parse info from message
content_type, chat_type, chat_id = telepot.glance2(msg)
# Open BD of the group
birthdayBD = shelve.open("BD" + str(chat_id))
# Stores user name
userName = msg['from']['first_name'] + " " + msg['from']['last_name']
# Stores original message
command = msg['text'].split(' ')
if(len(command) == 3):
try:
day = int(command[1])
month = int(command[2])
except TypeError:
print("Can't convert string to int")
return 0
if(day > 0 and day <= 31 and month > 0 and month <= 12):
birthdayBD[str(msg['from']['id'])] = [userName, day, month]
birthdayBD.close()
bot.sendMessage(chat_id, "Birthday stored.")
updateScheduler()
else:
bot.sendMessage(chat_id, "Bad formating, try again using '/bday dd mm' \ndd = day \nmm = month ")
return 0
示例12: handle_message
def handle_message(msg):
global active, bigrams, trigrams, weight, aB, aT, aW, mB, mT, mW, tB, tT, tW
msg_type, chat_type, chat_id = telepot.glance2(msg)
if msg_type != 'text':
return
input = msg['text']
reply_id = chat_id
if "/changebot_first" in input and active!='first':
bigrams, trigrams, weight = aB, aT, aW
active = 'first'
print "first loaded"
bot.sendMessage(reply_id, "first bot here")
elif "/changebot_second" in input and active!='second':
bigrams, trigrams, weight = mB, mT, mW
active = 'second'
print "second loaded"
bot.sendMessage(reply_id, "second bot here")
elif "/changebot_third" in input and active!='third':
bigrams, trigrams, weight = tB, tT, tW
active = 'third'
print "third loaded"
bot.sendMessage(reply_id, "third bot here")
else:
try:
bot.sendMessage(reply_id, genSentence(input, weight, bigrams, trigrams))
except:
bot.sendMessage(reply_id, "U WOT M8?")
示例13: handle
def handle(msg):
content_type, chat_type, chat_id = telepot.glance2(msg)
chat_id = msg['chat']['id']
command = msg['text']
if '@' in command:
command, botname = command.split('@')
command = command.replace("/", "")
if command == "start":
bot.sendMessage(chat_id, "Send /rrr to see if the RRR summerbar is currently open.\nAlso don't slap pandas 🐼")
if command.lower() == 'rrr':
url = "https://afternoondelight.de/rrr/status"
page = urllib.urlopen(url).read()
data = json.loads(page)
#print(data["status"])
if data["status"] == "closed":
bot.sendMessage(chat_id, "RRR is closed")
elif data["status"] == "open":
bot.sendMessage(chat_id, "RRR is open")
else:
bot.sendMessage(chat_id, "something's wrong...")
示例14: on_message
def on_message(self, msg):
flavor = telepot.flavor(msg)
if flavor == 'inline_query':
query_id, from_id, query_string = telepot.glance2(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.glance2(msg, flavor=flavor)
print(self.id, ':', 'Chosen Inline Result:', result_id, from_id, query_string)
示例15: answer
def answer(msg):
flavor = telepot.flavor(msg)
if flavor == 'inline_query':
query_id, from_id, query = telepot.glance2(msg, flavor=flavor)
if from_id != USER_ID:
print 'Unauthorized user:', from_id
return
examine(msg, 'InlineQuery')
articles = [InlineQueryResultArticle(
id='abc', title='HK', message_text='Hong Kong', url='https://www.google.com', hide_url=True),
InlineQueryResultArticle(
id='def', title='SZ', message_text='Shenzhen', url='https://www.yahoo.com')]
photos = [InlineQueryResultPhoto(
id='123', photo_url='https://core.telegram.org/file/811140934/1/tbDSLHSaijc/fdcc7b6d5fb3354adf', thumb_url='https://core.telegram.org/file/811140934/1/tbDSLHSaijc/fdcc7b6d5fb3354adf'),
{'type': 'photo',
'id': '345', 'photo_url': 'https://core.telegram.org/file/811140184/1/5YJxx-rostA/ad3f74094485fb97bd', 'thumb_url': 'https://core.telegram.org/file/811140184/1/5YJxx-rostA/ad3f74094485fb97bd', 'caption': 'Caption', 'title': 'Title', 'message_text': 'Message Text'}]
""""
gifs = [InlineQueryResultGif(
id='ghi', gif_url='http://www.animalstown.com/animals/g/gnu/coloring-pages/gnu-color-page-6.gif', thumb_url='http://www.animalstown.com/animals/g/gnu/coloring-pages/gnu-color-page-6.gif'),
{'type': 'gif',
'id': 'jkl', 'gif_url': 'http://img2.colorirgratis.com/gnu-na-savana-africana_49d5b597bc78d-p.gif', 'thumb_url': 'http://img2.colorirgratis.com/gnu-na-savana-africana_49d5b597bc78d-p.gif'}]
"""
# InlineQueryResultVideo(
# id='jkl', video_url='', mime_type='')
results = random.choice([articles, photos])
bot.answerInlineQuery(query_id, results, cache_time=20, is_personal=True, next_offset='5')
else:
raise telepot.BadFlavor(msg)