本文整理汇总了Python中telegram.Bot.sendMessage方法的典型用法代码示例。如果您正苦于以下问题:Python Bot.sendMessage方法的具体用法?Python Bot.sendMessage怎么用?Python Bot.sendMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类telegram.Bot
的用法示例。
在下文中一共展示了Bot.sendMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: help_command
# 需要导入模块: from telegram import Bot [as 别名]
# 或者: from telegram.Bot import sendMessage [as 别名]
def help_command(bot: telegram.Bot, update: telegram.Update):
message = start_message + "\n\n"
for commando in CommandHandlerWithHelp.helps:
message += '/' + commando + ' - ' + CommandHandlerWithHelp.helps[
commando] + '\n'
bot.sendMessage(update.message.chat_id, message)
Updates.get_updates().botan.track(update.message, 'help')
示例2: join
# 需要导入模块: from telegram import Bot [as 别名]
# 或者: from telegram.Bot import sendMessage [as 别名]
def join(bot: Bot, update):
"""Unisciti a una partita."""
game = findgamebyid(update.message.chat.id)
# Nessuna partita in corso
if game is None:
bot.sendMessage(update.message.chat.id, s.error_no_games_found, parse_mode=ParseMode.MARKDOWN)
return
# Fase di join finita
if game.phase != 'Join':
game.message(s.error_join_phase_ended)
return
p = game.findplayerbyid(update.message.from_user['id'])
# Giocatore già in partita
if p is not None:
game.message(s.error_player_already_joined)
return
# Giocatore senza username
if update.message.from_user.username is None:
game.message(s.error_no_username)
return
p = Player(game, update.message.from_user.id, update.message.from_user.username)
try:
p.message(s.you_joined.format(game=game.name, adminname=game.admin.tusername if game.admin is not None else p.tusername))
except Unauthorized:
# Bot bloccato dall'utente
game.message(s.error_chat_unavailable)
return
# Aggiungi il giocatore alla partita
game.joinplayer(p)
# Salva
game.save()
示例3: bug
# 需要导入模块: from telegram import Bot [as 别名]
# 或者: from telegram.Bot import sendMessage [as 别名]
def bug(bot: telegram.Bot, update: telegram.Update):
"""
:param bot:
:param update:
:return:
"""
chat_id = update.message.chat_id
user_id = update.message.from_user.id
try:
state = State(bot, chat_id, user_id, bug_conversation, bug_done)
state['command'] = update.message.text
state['from'] = update.message.from_user.name
keyboard = telegram.ReplyKeyboardMarkup([['app'], ['site'],
['anders']])
bot.sendMessage(chat_id, "Waar wil je een tip of een top voor "
"sturen?\napp/bot/site/anders",
reply_to_message_id=update.message.message_id,
reply_markup=keyboard)
Updates.get_updates().botan.track(update.message, 'bug')
except MultipleConversationsError:
bot.sendMessage(chat_id, "Er is al een commando actief je kunt dit "
"commando niet starten.\n"
" type /cancel om het vorige commando te "
"stoppen te stoppen",
reply_to_message_id=update.message.message_id)
Updates.get_updates().botan.track(update.message, 'incorrect_bug')
示例4: cancel
# 需要导入模块: from telegram import Bot [as 别名]
# 或者: from telegram.Bot import sendMessage [as 别名]
def cancel(bot: telegram.Bot, update: telegram.Update):
"""
:param bot:
:param update:
:return:
"""
chat_id = update.message.chat_id
user_id = update.message.from_user.id
h = str(user_id) + str(chat_id)
try:
state = State.states[h]
state.cancel()
except KeyError:
kb = telegram.ReplyKeyboardHide()
if update.message.chat_id > 0:
keyboard = DEFAULT_KEYBOARD
kb = telegram.ReplyKeyboardMarkup(keyboard,
one_time_keyboard=False,
selective=True)
bot.sendMessage(chat_id, "Er is geen commando actief.",
reply_to_message_id=update.message.message_id,
reply_markup=kb)
Updates.get_updates().botan.track(update.message, 'incorrect_cancel')
else:
kb = telegram.ReplyKeyboardHide()
if update.message.chat_id > 0:
keyboard = DEFAULT_KEYBOARD
kb = telegram.ReplyKeyboardMarkup(keyboard,
one_time_keyboard=False,
selective=True)
bot.sendMessage(update.message.chat_id, "Het commando is gestopt.",
reply_to_message_id=update.message.message_id,
reply_markup=kb)
Updates.get_updates().botan.track(update.message, 'cancel')
示例5: set_url_conversation
# 需要导入模块: from telegram import Bot [as 别名]
# 或者: from telegram.Bot import sendMessage [as 别名]
def set_url_conversation(bot: telegram.Bot, update: telegram.Update, state):
s = state.get_state()
keyboard = None
message = 'unexpected input!!'
if s == 0:
if update.message.text in ['hint', 'opdracht', 'nieuws']:
message = 'Wat is de url zonder de id?\n bijv. ' \
'http://www.jotihunt.net/groep/opdracht.php?MID='
state['soort'] = update.message.text
else:
message = 'kies uit hint, opdracht of nieuws. of /cancel om ' \
'terug te gaan.'
if s == 1:
state['url'] = update.message.text
s.done()
message = 'De url is aangepast voor ' + state['soort']
if keyboard is not None:
kb = telegram.ReplyKeyboardMarkup(keyboard, one_time_keyboard=True,
selective=True)
bot.sendMessage(update.message.chat_id, message,
reply_to_message_id=update.message.message_id,
reply_markup=kb)
else:
kb = telegram.ReplyKeyboardHide()
if update.message.chat_id > 0:
keyboard = DEFAULT_KEYBOARD
kb = telegram.ReplyKeyboardMarkup(keyboard, one_time_keyboard=False,
selective=True)
bot.sendMessage(update.message.chat_id, message,
reply_to_message_id=update.message.message_id,
reply_markup=kb)
示例6: set_phpsessid
# 需要导入模块: from telegram import Bot [as 别名]
# 或者: from telegram.Bot import sendMessage [as 别名]
def set_phpsessid(bot: telegram.Bot, update: telegram.Update):
chat_id = update.message.chat_id
user_id = update.message.from_user.id
try:
state = State(bot, chat_id, user_id, phpsessid_conversation,
phpsessid_done)
state['command'] = update.message.text
state['from'] = update.message.from_user.name
message = 'stap 1: login op jotihunt.net\n ' \
'stap2: zoek uit hoe je cookies van jothunt.net uitleest in je browser. \n ' \
'stap 3: ga op zook naar de cookie met de naam PHPSESSID.\n ' \
'stap 4: plak de waarde hier om de cookie te verversen van de bot.\n' \
' of /cancel om te stoppen'
bot.sendMessage(chat_id, message,
reply_to_message_id=update.message.message_id)
# TODO add a keyboard
Updates.get_updates().botan.track(update.message, 'phpsessid')
except MultipleConversationsError:
bot.sendMessage(chat_id, "Er is al een commando actief je kunt dit "
"commando niet starten.\n"
" type /cancel om het vorige commando te "
"stoppen te stoppeny",
reply_to_message_id=update.message.message_id)
Updates.get_updates().botan.track(update.message,
'incorrect_phpsessid')
示例7: save
# 需要导入模块: from telegram import Bot [as 别名]
# 或者: from telegram.Bot import sendMessage [as 别名]
def save(bot: Bot, update):
"""Salva una partita su file."""
game = findgamebyid(update.message.chat.id)
if game is not None:
game.save()
else:
bot.sendMessage(update.message.chat.id, s.error_no_games_found, parse_mode=ParseMode.MARKDOWN)
示例8: debug
# 需要导入模块: from telegram import Bot [as 别名]
# 或者: from telegram.Bot import sendMessage [as 别名]
def debug(bot: Bot, update):
"""Visualizza tutti i ruoli e gli id."""
if __debug__:
game = findgamebyid(update.message.chat.id)
if game is not None:
game.revealallroles()
else:
bot.sendMessage(update.message.chat.id, s.error_no_games_found, parse_mode=ParseMode.MARKDOWN)
示例9: phpsessid_conversation
# 需要导入模块: from telegram import Bot [as 别名]
# 或者: from telegram.Bot import sendMessage [as 别名]
def phpsessid_conversation(bot: telegram.Bot, update: telegram.Update, state):
s = state.get_state()
if s == 0:
state['cookie'] = update.message.text
state.done()
bot.sendMessage(update.message.chat_id,
update.message.from_user.name + ' de cookie is '
'aangepast.')
示例10: debugchangerole
# 需要导入模块: from telegram import Bot [as 别名]
# 或者: from telegram.Bot import sendMessage [as 别名]
def debugchangerole(bot: Bot, update):
"""Cambia il ruolo a un giocatore."""
if __debug__:
game = findgamebyid(update.message.chat.id)
if game is not None:
cmd = update.message.text.split(' ', 2)
game.changerole(game.findplayerbyusername(cmd[1]), globals()[cmd[2]])
else:
bot.sendMessage(update.message.chat.id, s.error_no_games_found, parse_mode=ParseMode.MARKDOWN)
示例11: error
# 需要导入模块: from telegram import Bot [as 别名]
# 或者: from telegram.Bot import sendMessage [as 别名]
def error(bot, update, error):
try:
ch_id = "27002116"
starter = Bot(token=token)
txt = "An error happened"
starter.sendMessage(ch_id, text=txt)
except:
pass
logger.warn('Update "%s" caused error "%s"' % (update, error))
示例12: test
# 需要导入模块: from telegram import Bot [as 别名]
# 或者: from telegram.Bot import sendMessage [as 别名]
def test(bot: telegram.Bot, update: telegram.Update):
bot.sendMessage(update.message.chat_id, 'de bot is online')
if update.message.chat_id > 0:
url = Updates.get_updates().botan.shorten('http://google.com',
update.message.from_user.id)
else:
url = 'http://google.com'
bot.sendMessage(update.message.chat_id, url)
Updates.get_updates().botan.track(update.message, 'test')
示例13: load
# 需要导入模块: from telegram import Bot [as 别名]
# 或者: from telegram.Bot import sendMessage [as 别名]
def load(bot: Bot, update):
"""Carica una partita salvata."""
game = findgamebyid(update.message.chat.id)
if game is not None:
bot.sendMessage(update.message.chat.id, s.error_game_in_progress, parse_mode=ParseMode.MARKDOWN)
return
file = open(str(update.message.chat.id) + ".p", "rb")
game = pickle.load(file)
inprogress.append(game)
game.message(s.game_loaded)
示例14: endjoin
# 需要导入模块: from telegram import Bot [as 别名]
# 或者: from telegram.Bot import sendMessage [as 别名]
def endjoin(bot: Bot, update):
"""Termina la fase di join e inizia quella di votazione."""
game = findgamebyid(update.message.chat.id)
if game is not None and game.phase == 'Join':
if update.message.from_user.id == game.admin.tid:
game.message(s.join_phase_ended)
game.startpreset()
else:
game.message(s.error_not_admin)
else:
bot.sendMessage(update.message.chat.id, s.error_no_games_found, parse_mode=ParseMode.MARKDOWN)
示例15: start
# 需要导入模块: from telegram import Bot [as 别名]
# 或者: from telegram.Bot import sendMessage [as 别名]
def start(bot: telegram.Bot, update: telegram.Update):
if update.message.chat_id > 0:
keyboard = telegram.ReplyKeyboardMarkup(DEFAULT_KEYBOARD,
one_time_keyboard=False)
bot.sendMessage(update.message.chat_id, start_message,
reply_markup=keyboard)
else:
bot.sendMessage(update.message.chat_id, start_message)
x = authenticate()
x(lambda bot2, update2: print('authenticated:\n' + str(update.to_dict(
))))(bot, update)
Updates.get_updates().botan.track(update.message, 'start')