forked from elees1219/LineBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.py
More file actions
268 lines (204 loc) · 11.5 KB
/
error.py
File metadata and controls
268 lines (204 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# -*- coding: utf-8 -*-
import time
import httplib
from enum import Enum
class mode(Enum):
FUNNY = 1
NORMAL = 1
class error(object):
MODE = mode.FUNNY
USER_MANUAL_URL = 'https://sites.google.com/view/jellybot'
class webpage(object):
@staticmethod
def no_content():
return u'沒有內容。'
class main(object):
@staticmethod
def incorrect_password_or_insufficient_permission():
return u'密碼錯誤或權限不足。'
@staticmethod
def invalid_thing(name_of_thing, thing):
return u'不合法的{}: {}。請查看使用說明書( {} )。'.format(name_of_thing, thing, error.USER_MANUAL_URL)
@staticmethod
def invalid_thing_with_correct_format(name_of_thing, correct_format, thing):
return u'不合法的{nt}: {t}。{nt}應為{fmt}。\n詳情請查看使用說明書( {um} )。'.format(nt=name_of_thing, t=thing, fmt=correct_format, um=error.USER_MANUAL_URL)
@staticmethod
def lack_of_thing(name_of_thing):
return u'缺少{nm}。請修正您所提供的{nm}成正確的格式。詳細說明請參閱使用說明書( {um} )'.format(nm=name_of_thing, um=error.USER_MANUAL_URL)
@staticmethod
def no_result():
return u'無結果。'
@staticmethod
def incorrect_channel(available_in_1v1=True, available_in_room=False, available_in_group=False):
return u'無法於此類型的頻道使用。請至下列頻道:\n{} {} {}\n詳細使用說明請參閱使用說明書( {} )'.format(
u'[ 私訊 ]' if available_in_1v1 else u'[ - ]',
u'[ 群組 ]' if available_in_group else u'[ - ]',
u'[ 房間 ]' if available_in_room else u'[ - ]',
error.USER_MANUAL_URL)
@staticmethod
def incorrect_param(param_name, correct):
return u'無法辨認。如果要使用這個功能,{}必須為{}。詳細使用方法請參閱使用說明書( {} )。'.format(param_name, correct, error.USER_MANUAL_URL)
@staticmethod
def unable_to_determine():
return u'無法判斷指令,請檢閱使用說明書( {} )。'.format(error.USER_MANUAL_URL)
@staticmethod
def pair_not_exist_or_insuffieicnt_permission():
return u'回覆組不存在,或字組改變權限不足。權限相關說明請參閱使用說明書( {} )。'.format(error.USER_MANUAL_URL)
@staticmethod
def invalid_length(thing, length):
return u'長度不符。{}的長度應為{}。'.format(thing, length)
@staticmethod
def unable_to_receive_user_id():
return u'因LINE政策問題,如果要使用這個功能的話,請先將LINE更新到v7.5.0以上,或是在私訊頻道中重試。\n\n詳細說明請點此查看: https://developers.line.me/messaging-api/obtaining-user-consent'
@staticmethod
def illegal_user_id():
return u'不合法的使用者ID。使用者'
@staticmethod
def line_account_data_not_found():
return u'無對應LINE帳號資料。'
@staticmethod
def user_name_not_found():
return u'找不到使用者名稱。'
@staticmethod
def miscellaneous(content):
return u'{}\n\n小水母使用說明: {}'.format(content, error.USER_MANUAL_URL)
class permission(object):
@staticmethod
def user_is_resticted():
return u'您遭到群組管理員設為「限制用戶」,所有系統功能將無法在這個群組觸發。若有任何問題,請洽詢管理員。'
@staticmethod
def restricted(permission=None):
return u'已限制的功能。{}'.format(
u'\n需求權限: {}+\n\n權限相關說明請參閱使用說明書( {} )'.format(permission, error.USER_MANUAL_URL) if permission is not None else u'')
class line_bot_api(object):
MAX_TEMPLATE_ACTIONS = 30
@staticmethod
def unable_to_receive_user_id():
return u'無法獲取LINE UID。請確定達成全部以下條件後重試:\n1.LINE版本7.5.0或以上\n2.已加入小水母好友\n\n如果全部符合上述條件仍然跳出此錯誤訊息的話,請輸入"小水母"填寫問題回報單。'
@staticmethod
def illegal_room_group_id(illegal_gid):
return error.main.invalid_thing_with_correct_format(u'LINE房間/群組', u'C(群組)或R(房間)開頭,並且長度為33字元,後32碼為0~9或a~f.', illegal_gid)
@staticmethod
def illegal_user_id(illegal_uid):
return error.main.invalid_thing_with_correct_format(u'LINE用戶ID', u'U開頭,並且長度為33字元,後32碼為0~9或a~f.', illegal_uid)
@staticmethod
def text_length_too_long(length, max_length, external_link):
return u'因訊息長度({}字)超過LINE API限制({}字),故無法顯示。請點下方連結以查看訊息。\n{}'.format(length, max_length, external_link)
@staticmethod
def too_many_newlines(newlines, max_newlines, external_link):
return u'因訊息行數({}行)超過最大限制({}行),故不顯示訊息。請點下方連結以查看訊息。\n{}'.format(newlines, max_newlines, external_link)
@staticmethod
def too_many_linked_words(count):
MAX = error.line_bot_api.MAX_TEMPLATE_ACTIONS
return u'因相關關鍵字數量({}個)超過系統限制({}個),故無法顯示。請刪除{}組相關關鍵字以後重試。'.format(count, MAX, count - MAX)
class oxford_api(object):
@staticmethod
def no_result(vocabulary):
return u'No result of {}.'.format(vocabulary)
@staticmethod
def err_with_status_code(status_code):
return u'An error has occurred while querying the data. Status Code: {} ({})'.format(status_code, httplib.responses[status_code])
@staticmethod
def disabled():
return u'Oxford dictionary has beed disabled. The reason might be an illegal api key or over quota.'
@staticmethod
def sense_not_found():
return u'No sense found in the entry.'
class mongo_db(object):
@staticmethod
def op_fail(err_instance):
return u'資料庫指令執行失敗。\n錯誤碼: {}\n錯誤訊息: {}'.format(err_instance.code, err_instance.message)
class sys_command(object):
@staticmethod
def unable_to_parse(result):
return u'傻逼,說明書看好看滿再來叫我做事,都沒看好就在那邊想打指令,Hen煩捏!\n\n{}'.format(result)
@staticmethod
def parameter_error(index, content):
if error.MODE == mode.FUNNY:
return u'你第{}個參數手殘打錯了,你看看: {}'.format(index, content)
else:
return u'參數{}發生錯誤,請查閱說明書以獲取使用方法。錯誤訊息: {}'.format(index, content)
@staticmethod
def must_https(obj):
return u'必須是https連結。({})'.format(obj)
@staticmethod
def must_gt_0(obj):
return u'整數需要大於0。({} - {})'.format(type(obj), obj)
@staticmethod
def must_int(obj):
return u'必須是整數或整數陣列。({} - {})'.format(type(obj), obj)
@staticmethod
def must_sha(obj):
return u'必須是SHA224雜湊結果。({})'.format(obj)
@staticmethod
def lack_of_parameters(indexes=None):
if indexes is None:
indexes = u'參數'
else:
indexes = u'、'.join([u'參數{}'.format(num) for num in indexes])
return error.main.lack_of_thing(indexes)
@staticmethod
def syntax_error(function_code):
return u'語法有誤。請檢查輸入的指令是否正確。\n嘗試使用功能代號: {}\n\n使用說明書: {}'.format(function_code, error.USER_MANUAL_URL)
@staticmethod
def action_not_implemented(function_code, match_at, action_text):
return u'於{}的驗證式第{}句中,發生未定義的行為: {}。請檢查語法是否正確。'.format(function_code, match_at, action_text)
@staticmethod
def regex_not_implemented(function_code, match_at, regex):
return u'未定義{}的驗證式第{}句({})的處理。請檢查語法是否正確。'.format(function_code, match_at, regex)
@staticmethod
def same_source_target(gid):
return u'指令來源和目的地不得相同。({})'.format(gid)
@staticmethod
def no_available_target_pair():
return u'指令執行失敗,無可用回覆組。'
@staticmethod
def unknown_func_K_ranking_category(obj):
return u'不明的排名種類。({})'.format(obj)
@staticmethod
def unknown_func_P_record_category(obj):
return u'不明的系統紀錄種類。({})'.format(obj)
@staticmethod
def unknown_func_GA_group_config(obj):
return u'不明的系統設定種類。({})'.format(obj)
@staticmethod
def unknown_func_GA2_permission(obj):
return u'不明的使用者權限代號。({})'.format(obj)
@staticmethod
def unknown_func_L_category(obj):
return u'不明的最近資料種類。({})'.format(obj)\
@staticmethod
def unknown_func_W_output_type(obj):
return u'不明的天氣資料輸出種類。({})'.format(obj)
@staticmethod
def unknown_func_W_action(obj):
return u'不明的天氣資料操作種類。({})'.format(obj)
@staticmethod
def unknown_func_STK_ranking_category(obj):
return u'不明的貼圖排行種類。({})'.format(obj)
@staticmethod
def func_C_currency_symbol_unrecognizable(obj):
return u'無法分析貨幣種類。({})'.format(obj)
class string_calculator(object):
@staticmethod
def result_is_not_numeric(org_text=None):
return u'計算結果為非數字型態,請重新檢查輸入的算式是否正確。{}'.format(
'' if org_text is None else '\n資料型態: {}\n原始字串: {}'.format(type(org_text), org_text))
@staticmethod
def error_on_calculating(ex):
return u'發生錯誤,計算失敗。\n錯誤訊息: {}'.format(ex.message)
@staticmethod
def calculation_timeout(timeout_sec, org_text=None):
return u'因計算超時({}秒),故終止運算。請嘗試拆解算式以後重新計算。{}'.format(
timeout_sec,
u'' if org_text is None else u'\n資料型態: {}\n原始字串: {}'.format(type(org_text), org_text))
@staticmethod
def wrong_format_to_calc_equations():
return u'方程式計算格式錯誤。請確認輸入格式為:\n第一行 - 有使用的變數,以逗號分隔(例: x, y)\n第二行以後 - 方程式,例如:\n 2x+3y=7\n 5x+8=9'
@staticmethod
def overflow(org_text=None):
return u'發生溢位。請嘗試拆解算式以後重新計算。{}'.format(
u'' if org_text is None else u'\n原始字串: {}'.format(org_text))
@staticmethod
def unknown_calculate_type():
return u'無法辨認要使用的計算項目。正確格式請參閱使用說明書( {} )'.format(error.USER_MANUAL_URL)