diff --git a/bot.py b/bot.py
index 0d0edf1..4035e0f 100644
--- a/bot.py
+++ b/bot.py
@@ -52,39 +52,39 @@ def on_chat(msg):
if user.check_online() == True:
user.send_answer(msg['text'], '')
- elif command[0] == '/start' or command[0] == '重新整理🔃' or command[0] == '回主畫面🏠':
+ elif command[0] == '/start' or command[0] == '主畫面🏠':
if user.check_online() == True:
user.display_main()
- elif command[0] == '/question' or command[0] == '查看題庫📝' or command[0] == '回到題庫📝' or command[0] == '重新載入🔃':
+ elif command[0] == '/question' or command[0] == '題庫📝' or command[0] == '更新🔃':
if user.check_online() == True:
if len(command) > 1:
user.display_question(command[1])
else:
user.display_questions()
- elif command[0] == '/help' or command[0] == '提供幫助📚':
+ elif command[0] == '/help' or command[0] == '幫助📚':
if user.check_online() == True:
user.help_you()
- elif command[0] == '/password' or command[0] == '修改密碼💱':
+ elif command[0] == '/password' or command[0] == '改密碼💱':
if user.check_online() == True:
user.press_oldpassword()
- elif command[0] == '/logout' or command[0] == '登出帳號🚪':
+ elif command[0] == '/logout' or command[0] == '登出🚪':
user = kuser(chat_id, bot)
users[str(chat_id)] = user
user.logout_system()
elif user.question != '題外':
if user.check_online() == True:
- if command[0] == '/upload' or command[0] == '上傳答案📮':
+ if command[0] == '/upload' or command[0] == '交作業📮':
user.upload_answer()
- elif command[0] == '/result' or command[0] == '查看結果☑️':
+ elif command[0] == '/result' or command[0] == '看結果☑️':
user.list_results()
- elif command[0] == '/passer' or command[0] == '通過名單🌐':
+ elif command[0] == '/passer' or command[0] == '通過者🌐':
user.list_passers()
- elif command[0] == '回到題目📜':
+ elif command[0] == '回題目📜':
user.display_question(user.question)
else:
bot.sendMessage(chat_id, "快去寫扣啦!")
diff --git a/interface.py b/interface.py
index 3729c20..c0c15fd 100644
--- a/interface.py
+++ b/interface.py
@@ -2,7 +2,7 @@
# necessary modules
import os, requests, telepot
-from telepot.namedtuple import KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove
+from telepot.namedtuple import ReplyKeyboardMarkup, ReplyKeyboardRemove
# kCOJ API
import access
# configurations
@@ -31,15 +31,16 @@ class kuser:
self.status = '輸入密碼'
self.question = '題外'
self.username = text
- self.bot.sendMessage(self.chat_id, "輸入完可刪除訊息以策安全!\n請輸入您的密碼:", reply_markup=ReplyKeyboardRemove())
+ self.bot.sendMessage(self.chat_id, "輸入完可刪除訊息以策安全!\n"
+ "請輸入您的密碼:", reply_markup=ReplyKeyboardRemove())
def press_oldpassword(self):
self.status = '舊的密碼'
self.question = '題外'
self.bot.sendMessage(self.chat_id, "請輸入要原本的舊密碼:",
- reply_markup=ReplyKeyboardMarkup(keyboard=[
- [KeyboardButton(text="回主畫面🏠")]
- ], resize_keyboard=True))
+ reply_markup=ReplyKeyboardMarkup(keyboard=[
+ ["主畫面🏠"]
+ ], resize_keyboard=True))
def press_newpassword(self, text):
self.status = '修改密碼'
@@ -53,13 +54,13 @@ class kuser:
def change_password(self, text):
self.status = '正常使用'
self.question = '題外'
- if text == "回主畫面🏠":
+ if text == "主畫面🏠":
self.display_main()
else:
self.password = text
self.bot.sendMessage(self.chat_id, "修改成功" if self.api.change_password(self.password) == True else "修改失敗",
reply_markup=ReplyKeyboardMarkup(keyboard=[
- [KeyboardButton(text="回主畫面🏠")]
+ ["主畫面🏠"]
], resize_keyboard=True))
def login_kcoj(self, text):
@@ -81,9 +82,9 @@ class kuser:
if self.api.login_kcoj(self.username, self.password) == None:
self.question = '題外'
self.bot.sendMessage(self.chat_id, "郭老網站離線中!",
- reply_markup=ReplyKeyboardMarkup(keyboard=[
- [KeyboardButton(text="回主畫面🏠")]
- ], resize_keyboard=True))
+ reply_markup=ReplyKeyboardMarkup(keyboard=[
+ ["主畫面🏠"]
+ ], resize_keyboard=True))
return False
elif self.api.check_online() == True:
return True
@@ -117,9 +118,9 @@ class kuser:
"你今天寫扣了嗎?",
parse_mode='HTML',
reply_markup=ReplyKeyboardMarkup(keyboard=[
- [KeyboardButton(text="查看題庫📝"), KeyboardButton(text="重新整理🔃")],
- [KeyboardButton(text="登出帳號🚪"), KeyboardButton(text="修改密碼💱"), KeyboardButton(text="提供幫助📚")]
- ]))
+ ["題庫📝"],
+ ["登出🚪", "改密碼💱", "幫助📚"]
+ ], resize_keyboard=True))
def display_questions(self):
self.status = '正常使用'
@@ -130,13 +131,15 @@ class kuser:
q_str += "📗" if q_dict[key][1] == '期限未到' else "📕"
q_str += "" + key + " (到 " + q_dict[key][0] + ")\n [[" + q_dict[key][2] + "]] /question_" + key + "\n\n"
self.bot.sendMessage(self.chat_id, "💁 " + self.username + " /logout\n"
- "➖➖➖➖➖\n📝所有作業\n\n" + q_str + "➖➖➖➖➖\n"
+ "➖➖➖➖➖\n"
+ "📝所有作業\n\n" + q_str + \
+ "➖➖➖➖➖\n"
"你今天寫扣了嗎?",
parse_mode='HTML',
reply_markup=ReplyKeyboardMarkup(keyboard=[
- [KeyboardButton(text="回主畫面🏠"), KeyboardButton(text="重新載入🔃")],
- [KeyboardButton(text="登出帳號🚪"), KeyboardButton(text="修改密碼💱"), KeyboardButton(text="提供幫助📚")]
- ]))
+ ["主畫面🏠", "更新🔃"],
+ ["登出🚪", "改密碼💱", "幫助📚"]
+ ], resize_keyboard=True))
def display_question(self, number):
self.status = '查看題目'
@@ -145,18 +148,13 @@ class kuser:
q = self.api.list_questions()[number]
q_str = "📗" if q[1] == '期限未到' else "📕"
q_str += "**" + number + "** (到 " + q[0] + ")\n [[" + q[2] + "]]\n"
- k = [[KeyboardButton(text="回主畫面🏠"), KeyboardButton(text="回到題庫📝")]]
- k2 = []
- if q[1] == '期限未到':
- k2 += [KeyboardButton(text="上傳答案📮")]
- if q[2] == '已繳':
- k2 += [KeyboardButton(text="查看結果☑️")]
- k2 += [KeyboardButton(text="通過名單🌐")]
- k += [k2]
- k += [[KeyboardButton(text="登出帳號🚪"), KeyboardButton(text="修改密碼💱"), KeyboardButton(text="提供幫助📚")]]
self.bot.sendMessage(self.chat_id, q_str + "\n```\n" + content + "\n```",
parse_mode='Markdown',
- reply_markup=ReplyKeyboardMarkup(keyboard=k))
+ reply_markup=ReplyKeyboardMarkup(keyboard=[
+ ["主畫面🏠", "回題庫📝"],
+ ["交作業📮" if q[1] == '期限未到' else '', "看結果☑️" if q[2] == '已繳' else '', "通過者🌐"],
+ ["登出🚪", "改密碼💱", "幫助📚"]
+ ], resize_keyboard=True))
def help_you(self):
self.status = '正常使用'
@@ -175,43 +173,43 @@ class kuser:
"7. 我以我的人格擔保,不會使用您提供的資訊侵害您的權利\n\n"
"然後,附上厲害的 [郭老 Online Judge 傳送門](" + config.URL + ")", parse_mode='Markdown',
reply_markup=ReplyKeyboardMarkup(keyboard=[
- [KeyboardButton(text="回主畫面🏠")],
- [KeyboardButton(text="登出帳號🚪"), KeyboardButton(text="修改密碼💱"), KeyboardButton(text="提供幫助📚")]
- ]))
+ ["主畫面🏠"],
+ ["登出🚪", "改密碼💱", "幫助📚"]
+ ], resize_keyboard=True))
self.bot.sendMessage(self.chat_id, "專案授權方式採用 GPLv3\n"
"非常歡迎發 issue 送 PR owooo\n"
"原始碼被託管於 GitHub,大大們有空的話可以按個星星支持一下> <網址如下:\n"
"https://github.com/PinLin/kcoj_bot")
+
def upload_answer(self):
self.status = '上傳答案'
q = self.api.list_questions()[self.question]
q_str = "📗" if q[1] == '期限未到' else "📕"
q_str += "" + self.question + " (到 " + q[0] + ")\n [[" + q[2] + "]]\n"
self.bot.sendMessage(self.chat_id, q_str + "\n現在請把你的程式碼讓我看看(請別超過 20 MB)\n"
- "可以使用「文字訊息」或是「傳送檔案」的方式", parse_mode='HTML',
- reply_markup=ReplyKeyboardMarkup(keyboard=[
- [KeyboardButton(text="刪除作業⚔️")],
- [KeyboardButton(text="回主畫面🏠"), KeyboardButton(text="回到題目📜")]] if self.api.list_questions()[self.question][2] == '已繳' else [
- [KeyboardButton(text="回主畫面🏠"), KeyboardButton(text="回到題目📜")]
- ], resize_keyboard=True))
+ "可以使用「文字訊息」或是「傳送檔案」的方式", parse_mode='HTML',
+ reply_markup=ReplyKeyboardMarkup(keyboard=[
+ ["刪除作業⚔️"] if self.api.list_questions()[self.question][2] == '已繳' else [],
+ ["主畫面🏠", "回題目📜"]
+ ], resize_keyboard=True))
def send_answer(self, text, file_id):
self.status = '正常使用'
if text != '':
- if text == '回主畫面🏠':
+ if text == '主畫面🏠':
if self.check_online() == True:
self.display_main()
return
- elif text == '回到題目📜':
+ elif text == '回題目📜':
if self.check_online() == True:
self.display_question(self.question)
return
elif text == '刪除作業⚔️':
self.bot.sendMessage(self.chat_id, "移除成功" if self.api.delete_answer(self.question) == True else "移除失敗",
reply_markup=ReplyKeyboardMarkup(keyboard=[
- [KeyboardButton(text="回主畫面🏠"), KeyboardButton(text="回到題目📜")],
- [KeyboardButton(text="登出帳號🚪"), KeyboardButton(text="修改密碼💱"), KeyboardButton(text="提供幫助📚")]
- ]))
+ ["主畫面🏠", "回題目📜"],
+ ["登出🚪", "改密碼💱", "幫助📚"]
+ ], resize_keyboard=True))
return
else:
f = open(self.username + self.question + '.c', 'w')
@@ -223,24 +221,26 @@ class kuser:
if self.api.upload_answer(self.question, self.username + self.question + '.c') == True:
self.bot.sendMessage(self.chat_id, "上傳成功",
reply_markup=ReplyKeyboardMarkup(keyboard=[
- [KeyboardButton(text="回主畫面🏠"), KeyboardButton(text="回到題目📜")],
- [KeyboardButton(text="查看結果☑️")],
- [KeyboardButton(text="登出帳號🚪"), KeyboardButton(text="修改密碼💱"), KeyboardButton(text="提供幫助📚")]
- ]))
+ ["主畫面🏠", "回題目📜"],
+ ["看結果☑️"],
+ ["登出🚪", "改密碼💱", "幫助📚"]
+ ], resize_keyboard=True))
else:
self.bot.sendMessage(self.chat_id, "上傳失敗",
reply_markup=ReplyKeyboardMarkup(keyboard=[
- [KeyboardButton(text="回主畫面🏠"), KeyboardButton(text="回到題目📜")],
- [KeyboardButton(text="登出帳號🚪"), KeyboardButton(text="修改密碼💱"), KeyboardButton(text="提供幫助📚")]
- ]))
+ ["主畫面🏠", "回題目📜"],
+ ["登出🚪", "改密碼💱", "幫助📚"]
+ ], resize_keyboard=True))
os.remove(self.username + self.question + '.c')
def fail_send(self):
self.status = '正常使用'
self.bot.sendMessage(self.chat_id, "檔案不能超過 20 MB!上傳失敗",
- reply_markup=ReplyKeyboardMarkup(keyboard=[
- [KeyboardButton(text="回主畫面🏠"), KeyboardButton(text="回到題目📜")]
- ]))
+ reply_markup=ReplyKeyboardMarkup(keyboard=[
+ ["主畫面🏠", "回題目📜"],
+ ["登出🚪", "改密碼💱", "幫助📚"]
+ ], resize_keyboard=True))
+
def list_passers(self):
self.status = '正常使用'
q = self.api.list_questions()[self.question]
@@ -248,11 +248,12 @@ class kuser:
q_str += "" + self.question + " (到 " + q[0] + ")\n [[" + q[2] + "]]\n"
for passer in self.api.list_passers(self.question):
q_str += "\n" + passer
- self.bot.sendMessage(self.chat_id, q_str + "
", parse_mode='HTML',
- reply_markup=ReplyKeyboardMarkup(keyboard=[
- [KeyboardButton(text="回主畫面🏠"), KeyboardButton(text="回到題目📜")],
- [KeyboardButton(text="登出帳號🚪"), KeyboardButton(text="修改密碼💱"), KeyboardButton(text="提供幫助📚")]
- ]))
+ self.bot.sendMessage(self.chat_id, q_str + "",
+ parse_mode='HTML',
+ reply_markup=ReplyKeyboardMarkup(keyboard=[
+ ["主畫面🏠", "回題目📜"],
+ ["登出🚪", "改密碼💱", "幫助📚"]
+ ], resize_keyboard=True))
def list_results(self):
self.status = '正常使用'
@@ -263,11 +264,10 @@ class kuser:
q_str += "\n測試編號 " + result[0] + "
:"
q_str += "✔️ " if result[1] == '通過測試' else "❌ "
q_str += result[1]
- k = [[KeyboardButton(text="回主畫面🏠"), KeyboardButton(text="回到題目📜")]]
- k2 = []
- if q[1] == '期限未到':
- k2 += [KeyboardButton(text="上傳答案📮")]
- k2 += [KeyboardButton(text="通過名單🌐")]
- k += [k2]
- k += [[KeyboardButton(text="登出帳號🚪"), KeyboardButton(text="修改密碼💱"), KeyboardButton(text="提供幫助📚")]]
- self.bot.sendMessage(self.chat_id, q_str, parse_mode='HTML', reply_markup=ReplyKeyboardMarkup(keyboard=k))
\ No newline at end of file
+ self.bot.sendMessage(self.chat_id, q_str,
+ parse_mode='HTML',
+ reply_markup=ReplyKeyboardMarkup(keyboard=[
+ ["主畫面🏠", "回題目📜"],
+ ["交作業📮" if q[1] == '期限未到' else '', "通過者🌐"],
+ ["登出🚪", "改密碼💱", "幫助📚"]
+ ], resize_keyboard=True))
\ No newline at end of file