def start_command(self, bot, update, args):
user_id = update.message.from_user.id
chat= str(update.message.chat_id)
if str(user_id) in allowed_users.values() and chat != chats['group']:
self.store.new_draft(user_id)
bot.sendMessage(update.message.chat_id,parse_mode='Markdown',
text="Crearem una publicació per a compartir.\n\n\u0031\u20E3 El primer que heu de fer és enviar-me el *nom de la publicació*.\n\nSi no voleu continuar amb el procés, envieu /cancel.",
reply_markup=ReplyKeyboardHide())
else:
f_name = update.message.from_user.first_name
chat= str(update.message.chat_id)
if not function['production'] and chat != chats['group']:
bot.sendMessage(update.message.chat_id,
parse_mode='Markdown',
text= "Robot destinat a proves internes de Softcatalà. Si cerqueu el bot públic de Softcatalà el trobareu a @SoftcatalaBot.")
elif function['production'] and chat != chats['group']:
bot.sendMessage(update.message.chat_id,
text= str(f_name) + ", no teniu permisos per utilitzar aquesta ordre. Les ordres que teniu disponibles ara mateix són: /baixa /android /ios /tdesktop i /help.")
else:
bot.sendMessage(update.message.chat_id,
text= "No es permet crear publicacions des del grup.")
python类ReplyKeyboardHide()的实例源码
def admin_command(self, bot, update):
user_id = update.message.from_user.id
f_name = update.message.from_user.first_name
if str(user_id) in allowed_users.values():
bot.sendMessage(update.message.chat_id,parse_mode='Markdown',
text= f_name + ", sou administrador i podeu utilitzar les comandes:\n\n\U0001F4DD *Publicar* (crear esdeveniments, notícies, projectes i actualitzar paquets): /post\n\n\U0001F4C8 *Estadístiques* (resum estadístic i rebre el fitxer): /stats\n\n\U0001F5C3 *Baixar paquets* desats en local: /getfiles\n\n*\U0001F50D Comprovar els paquets* desats al servidor de Telegram amb ID de fitxer: /testfiles\n\n\u00A9 Softcatalà, 2016",
reply_markup=ReplyKeyboardHide())
else:
if function['production']:
bot.sendMessage(update.message.chat_id,
text= str(f_name) + ", no teniu permisos per utilitzar aquesta ordre. Les ordres que teniu disponibles ara mateix són: /baixa /android /ios /tdesktop i /help.")
else:
bot.sendMessage(update.message.chat_id,
text= "Robot destinat a proves internes de Softcatalà. Si cerqueu el bot públic de Softcatalà el trobareu a @SoftcatalaBot.")
def cancel_command(self, bot, update):
user_id = update.message.from_user.id
draft = self.store.get_draft(user_id)
if draft:
self.store.remove_draft(update.message.from_user.id)
bot.sendMessage(
update.message.chat_id,
text="\U0001F5D1 S'ha cancel·lat la creació de la publicació.",
reply_markup=ReplyKeyboardHide()
)
else:
if str(user_id) in allowed_users.values():
bot.sendMessage(
update.message.chat_id,
text="\u26A0\uFE0F No hi ha res a cancel·lar.\nAquesta comanda només funciona quan s'ha iniciat la creació d'una publicació.",
reply_markup=ReplyKeyboardHide()
)
elif function['production']:
f_name = update.message.from_user.first_name
bot.sendMessage(
update.message.chat_id,
text= str(f_name) + ", no teniu permisos per utilitzar aquesta ordre. Les ordres que teniu disponibles ara mateix són: /baixa /android /ios /tdesktop i /help.",
reply_markup=ReplyKeyboardHide()
)
else:
bot.sendMessage(
update.message.chat_id,
text="Robot destinat a proves internes de Softcatalà. Si cerqueu el bot públic de Softcatalà el trobareu a @SoftcatalaBot.",
reply_markup=ReplyKeyboardHide()
)
def send_stop(bot, update):
reply_markup = telegram.ReplyKeyboardHide()
bot.sendMessage(update.message.chat_id, text="Bye", reply_markup=reply_markup)
def send_stop(bot, update):
reply_markup = telegram.ReplyKeyboardHide()
bot.sendMessage(update.message.chat_id, text="Bye", reply_markup=reply_markup)
def start_command_callback(self, bot, update):
chat_id = update.message.chat_id
auth_url = self.vk.get_auth_url()
# Send first info messages
bot.sendMessage(chat_id=chat_id,
text=message.WELCOME(auth_url),
reply_markup=ReplyKeyboardHide())
bot.sendMessage(chat_id=chat_id, text=message.COPY_TOKEN)
# Create new client
client = Client(next_action=action.ACCESS_TOKEN,
chat_id=chat_id)
self.clients[chat_id] = client
client.persist()
def build_keyboard(self, keyboard):
built_keyboard = []
if keyboard:
built_keyboard = InlineKeyboardMarkup([[self._create_keyboard_button(element)] for element in traverse(ast.literal_eval(keyboard))])
else:
built_keyboard = ReplyKeyboardHide()
return built_keyboard
def testfiles_command(self, bot, update):
user_id = update.message.from_user.id
if str(user_id) in allowed_users.values():
testfiles= 0
#TEST ANDROID FILE_ID
f= open(paths['file_ids']+"android_file_id.txt","r")
fandroid= f.read(32)
f.close()
r = requests.get('https://api.telegram.org/bot' + params['token'] + '/getFile?file_id=' + fandroid)
output= r.json()
if output['ok']:
testandroid= ''
else:
testfiles+= 1
testandroid= ' \U0001F6AB *Android*\n'
#TEST IOS FILE_ID
f= open(paths['file_ids']+"ios_file_id.txt","r")
fios= f.read(32)
f.close()
r = requests.get('https://api.telegram.org/bot' + params['token'] + '/getFile?file_id=' + fios)
output= r.json()
if output['ok']:
testios= ''
else:
testfiles+= 1
testios= ' \U0001F6AB *iOS*\n'
#TEST TELEGRAM DESKTOP FILE_ID
f= open(paths['file_ids']+"tdesktop_file_id.txt","r")
ftdesktop= f.read(32)
f.close()
r = requests.get('https://api.telegram.org/bot' + params['token'] + '/getFile?file_id=' + ftdesktop)
output= r.json()
if output['ok']:
testtdesktop= ''
else:
testfiles+= 1
testtdesktop= ' \U0001F6AB *Telegram Desktop*\n'
if testfiles == 0:
bot.sendMessage(update.message.from_user.id,
parse_mode='Markdown',
text= "Els *file_id* dels tres fitxers són correctes.\nNo hi ha *cap* error.")
elif testfiles > 0:
bot.sendMessage(update.message.from_user.id,
parse_mode='Markdown',
text= "Errors als *file_id* dels paquets de llengua: " +str(testfiles) + "\n Fallen els paquets:\n" + testandroid + testios + testtdesktop)
elif function['production']:
f_name = update.message.from_user.first_name
bot.sendMessage(
update.message.chat_id,
text= str(f_name) + ", no teniu permisos per utilitzar aquesta ordre. Les ordres que teniu disponibles ara mateix són: /baixa /android /ios /tdesktop i /help.",
reply_markup=ReplyKeyboardHide()
)
else:
bot.sendMessage(
update.message.chat_id,
text="Robot destinat a proves internes de Softcatalà. Si cerqueu el bot públic de Softcatalà el trobareu a @SoftcatalaBot.",
reply_markup=ReplyKeyboardHide()
)
def getfiles_command(self, bot, update):
user_id = update.message.from_user.id
if str(user_id) in allowed_users.values():
bot.sendMessage(update.message.chat_id,
parse_mode='Markdown',
text= "Us envio els fitxers desats al servidor (còpia de seguretat) per a cada plataforma. Veureu que hi ha la versió normal i la versió desada amb la data (els dos fitxers han de ser iguals)."
)
#SEND LOCAL ANDROID FILES
f= open(paths['versions']+"android_version.txt","r")
and_version= f.read(10)
f.close()
and_version2= str.replace(and_version, "/", "-")
android_file= open(paths['local_packs']+'strings.xml', 'rb')
bot.sendDocument(update.message.chat_id,
document=android_file)
android_file_v= open(paths['local_packs']+'strings-' +and_version2+ '.xml', 'rb')
bot.sendDocument(update.message.chat_id,
document=android_file_v)
#SEND LOCAL IOS FILES
f= open(paths['versions']+"ios_version.txt","r")
ios_version= f.read(10)
f.close()
ios_version2= str.replace(ios_version, "/", "-")
ios_file= open(paths['local_packs']+'Localizable-ios.strings', 'rb')
bot.sendDocument(update.message.chat_id,
document=ios_file)
ios_file_v= open(paths['local_packs']+'Localizable-ios-' +and_version2+ '.strings', 'rb')
bot.sendDocument(update.message.chat_id,
document=ios_file_v)
#SEND LOCAL TELEGRAM DESKTOP FILES
f= open(paths['versions']+"tdesktop_version.txt","r")
tdesk_version= f.read(10)
f.close()
tdesk_version2= str.replace(tdesk_version, "/", "-")
tdesktop_file= open(paths['local_packs']+'tdesktop.strings', 'rb')
bot.sendDocument(update.message.chat_id,
document=tdesktop_file)
tdesktop_file_v= open(paths['local_packs']+'tdesktop-' +tdesk_version2+ '.strings', 'rb')
bot.sendDocument(update.message.chat_id,
document=tdesktop_file_v)
elif function['production']:
f_name = update.message.from_user.first_name
bot.sendMessage(
update.message.chat_id,
text= str(f_name) + ", no teniu permisos per utilitzar aquesta ordre. Les ordres que teniu disponibles ara mateix són: /baixa /android /ios /tdesktop i /help.",
reply_markup=ReplyKeyboardHide()
)
else:
bot.sendMessage(
update.message.chat_id,
text="Robot destinat a proves internes de Softcatalà. Si cerqueu el bot públic de Softcatalà el trobareu a @SoftcatalaBot.",
reply_markup=ReplyKeyboardHide()
)
def ios_command(self, bot, update):
user_id = update.message.from_user.id
if str(user_id) in allowed_users.values() or function['production']:
f= open(paths['versions']+"ios_version.txt","r")
ios_version= f.read(10)
f.close()
tios= "Heu triat el paquet de llengua per a *Telegram iOS*.\n\nUs enviem la versió " + str(ios_version) + " del paquet. Podeu demanar-ne la versió més actual sempre que ho desitgeu.\n\n*Instruccions d'instal·lació*:\n1r. *Baixeu el fitxer* «Localizable-ios.strings» enviat després d'aquest missatge prement la icona de la fletxa cap avall.\n2n. Premeu sobre el fitxer baixat i trieu «Apply localization file», «Aplicar traducción» o «Aplica el paquet de llengua», segons el cas.\n\nSi voleu que us avisem quan hi hagi una versió nova del paquet de llengua, o notícies de Softcatalà, uniu-vos al [Canal de Softcatalà](https://telegram.me/Softcatala)."
f= open(paths['file_ids']+"ios_file_id.txt","r")
fios= f.read(32)
f.close()
bot.sendMessage(update.message.chat_id,
parse_mode='Markdown',
disable_web_page_preview=True,
text= tios
)
bot.sendDocument(update.message.chat_id,
document=fios)
user_id = update.message.from_user.id
today= datetime.now()
dayraw = today.day
if int(dayraw) < 10:
day = '0' + str(dayraw)
else:
day = str(dayraw)
monthraw = today.month
if int(monthraw) < 10:
month = '0' + str(monthraw)
else:
month = str(monthraw)
year = today.year
today2= day + '/' + month + '/' + str(year)
stat= today2 + ';user#id' + str(user_id) + ';' + str(ios_version) + ';iOS;bot;command'
with open(paths['stats']+'stats.csv','a',newline='') as f:
writer=csv.writer(f)
writer.writerow([stat])
else:
bot.sendMessage(
update.message.chat_id,
text="Robot destinat a proves internes de Softcatalà. Si cerqueu el bot públic de Softcatalà el trobareu a @SoftcatalaBot.",
reply_markup=ReplyKeyboardHide()
)
def tdesktop_command(self, bot, update):
user_id = update.message.from_user.id
if str(user_id) in allowed_users.values() or function['production']:
f= open(paths['versions']+"tdesktop_version.txt","r")
tdesk_version= f.read(10)
f.close()
ttdesktop= "Heu triat el paquet de llengua per a *Telegram Desktop*.\n\nUs enviem la versió " + str(tdesk_version) + " del paquet. Podeu demanar-ne la versió més actual sempre que ho desitgeu.\n\n*Intruccions d'instal·lació*:\n1r. *Baixeu el fitxer* «tdesktop.strings» enviat després d'aquest missatge i recordeu la carpeta on es troba, habitualment `./Baixades/Telegram Desktop` del vostre perfil d'usuari.\n2n. Aneu a la configuració del Telegram Desktop («Settings» o «Ajustes») i, *a l'aire, teclegeu* «loadlang».\n3r. Trieu el fitxer «tdesktop.strings» baixat al pas 1.\n4t. Confirmeu el reinici del Telegram Desktop.\n\n*Nota*: no esborreu de l'ordinador el fitxer que heu baixat.\n\nSi voleu que us avisem quan hi hagi una versió nova del paquet de llengua, o notícies de Softcatalà, uniu-vos al [Canal de Softcatalà](https://telegram.me/Softcatala)."
f= open(paths['file_ids']+"tdesktop_file_id.txt","r")
ftdesktop= f.read(32)
f.close()
bot.sendMessage(update.message.chat_id,
parse_mode='Markdown',
disable_web_page_preview=True,
text= ttdesktop
)
bot.sendDocument(update.message.chat_id,
document=ftdesktop)
user_id = update.message.from_user.id
today= datetime.now()
dayraw = today.day
if int(dayraw) < 10:
day = '0' + str(dayraw)
else:
day = str(dayraw)
monthraw = today.month
if int(monthraw) < 10:
month = '0' + str(monthraw)
else:
month = str(monthraw)
year = today.year
today2= day + '/' + month + '/' + str(year)
stat= today2 + ';user#id' + str(user_id) + ';' + str(tdesk_version) + ';tdesktop;bot;command'
with open(paths['stats']+'stats.csv','a',newline='') as f:
writer=csv.writer(f)
writer.writerow([stat])
else:
bot.sendMessage(
update.message.chat_id,
text="Robot destinat a proves internes de Softcatalà. Si cerqueu el bot públic de Softcatalà el trobareu a @SoftcatalaBot.",
reply_markup=ReplyKeyboardHide()
)
def process_vote_response(bot: telegram.Bot, update: telegram.Update):
# Message text comes from a reply keyboard.
# The keyboard options look like: "abcdefgh: Title of Poll",
# where "abcdefgh" is the poll tag.
t = update.message.text
uid = update.message.from_user.id
# Check if user has typed something into the text reply, instead of
# clicking a reply keyboard button like they should have.
if not re.match("^[a-z]{8}:", t):
bot.sendMessage(update.message.chat_id, text_vote_not_understood,
reply_markup=ReplyKeyboardHide())
return ConversationHandler.END
# Check if the given poll tag 1) exists, 2) is active,
# and 3) if the user is allowed to vote in that poll.
poll_tag = t[0:8]
q = Query()
poll = polls_db.get(q.tag == poll_tag)
if (poll is None) or (poll['active'] != True) or (
not user_is_in_chat(uid, poll['target_chat'], bot)):
bot.sendMessage(update.message.chat_id, text_no_such_vote,
reply_markup=ReplyKeyboardHide())
return ConversationHandler.END
# Check if user was already given a token for this poll.
q2 = Query()
existing_token = tokens_db.get(
q2.user_id == uid and q2.poll_tag == poll_tag)
if existing_token is None:
# Give new token
token = make_token(uid, poll_tag)
msg = text_new_token.format(title=poll['title'], url=poll['url'],
token=token)
bot.sendMessage(update.message.chat_id, msg,
reply_markup=ReplyKeyboardHide())
return ConversationHandler.END
else:
# Give existing token again
token = existing_token['token']
msg = text_existing_token.format(title=poll['title'], url=poll['url'],
token=token)
bot.sendMessage(update.message.chat_id, msg,
reply_markup=ReplyKeyboardHide())
return ConversationHandler.END
assert False # Should never reach here