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
| var CHANNEL_ACCESS_TOKEN=""
var google_sheet_url='https://docs.google.com/spreadsheets/d/1a2LjfrpoGb8dLYPX7piCsl0NEUMgiLIyxSrMAWSf0cA/edit?usp=sharing'; var spreadsheet = SpreadsheetApp.openByUrl(google_sheet_url); var sheet_translator = spreadsheet.getSheetByName("translator");
var Translate_N_Max=50 var Group_language_Max=12 var today = new Date();
function doPost(e) { var msg= JSON.parse(e.postData.contents); var replyToken = msg.events[0].replyToken; var type = msg.events[0].type; var userid=msg.events[0].source.userId; var groupid=msg.events[0].source.groupId; var Translate_N=translate_groupid_search_N(groupid);
if(type=='join'){ if(translate_vain_N()!="false"){ sheet_translator.getRange(4*translate_vain_N()+2,3,1,6).setValue(groupid); reply_message(replyToken,reply_bot_welcome); } else{ push_message_userid("目前已達到群組上限,請去檢查一下") reply_message(replyToken,reply_all_group_full); } } else if(type=='leave'){ sheet_cancel(Translate_N) } else if(type=="follow"){ reply_message(replyToken,reply_instruction); } else if(type=='postback'){ postbackMessage=msg.events[0].postback.data if(Translate_N!="false"){ if(String(sheet_translator.getSheetValues(4*Translate_N+1,2,1,1)[0][0])=="true"){ reply_message(replyToken,reply_reselect); } else{ var Language_list=translate_group_language(groupid); if(postbackMessage=="finish"){ if(Language_list.length==0){ reply_message(replyToken,[{'type': 'text','text': "錯誤:尚未設定語言\nError:Language not set yet"}]) } else{ sheet_translator.getRange(4*Translate_N+1,2,1,1).setValue("true") reply_message(replyToken,[{'type': 'text','text': "設定完成,可以開始交談\nSetup is complete,can start talking"}]) } } else if(postbackMessage=="reselect"){ sheet_cancel(Translate_N) sheet_translator.getRange(4*Translate_N+2,3,1,6).setValue(groupid); reply=[{'type': 'text','text': "重置完成,請重新點選\nReselect is complete,please reselect"},translate_reply[0]] reply_message(replyToken,reply) } else if(postbackMessage.replace(/[a-z-A-Z]*/, '').length==0){ if(Language_list.includes(postbackMessage)){ var reply=[{'type': 'text','text':'錯誤:不能設定重複的語言\nError:Cannot set duplicate language'}] reply_message(replyToken,reply); } else if(Language_list.length>=Group_language_Max){ var reply=[{'type': 'text','text':'錯誤:設定過多的語言\nError:Too many languages set'}] reply_message(replyToken,reply); } sheet_translator.getRange(4*Translate_N+3,3+Language_list.length,1,1).setValue(postbackMessage) var reply=[{'type': 'text','text':'語言(language):'+String(translate_group_language(groupid))}] reply_message(replyToken,reply); } } } } else if(type=='message' && msg.events[0].message.text!=null){ var userMessage = msg.events[0].message.text; if(userMessage.toLowerCase()=="instruction" || userMessage=="使用說明"){ reply_message(replyToken,reply_instruction); } else if(Translate_N!="false"){ if(String(sheet_translator.getSheetValues(4*Translate_N+1,2,1,1)[0][0])=="true"){ var Language_list=translate_group_language(groupid); for(i in Language_list){ if(i==0){output_str='【'+Language_list[0]+'】'+LanguageApp.translate(userMessage, "", Language_list[0])} else{ output_str=output_str+'\n【'+Language_list[i]+'】'+LanguageApp.translate(userMessage, "", Language_list[i]); } } sheet_translator.getRange(4*Translate_N+1,5,1,4).setValue(today); reply=[{'type': 'text','text':output_str}] reply_message(replyToken,reply); } else{ reply=[{'type': 'text','text':'錯誤:請先設定【完成】\nError:Please set 【Finish】 first'}] reply_message(replyToken,reply); } } } }
|