Skip to content

Commit

Permalink
修正telegrambot
Browse files Browse the repository at this point in the history
  • Loading branch information
estea8968 committed Dec 28, 2024
1 parent b72600a commit bdf53bb
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 60 deletions.
2 changes: 1 addition & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="google" value="notranslate">
<link rel="shortcut icon" href="static/favicon.ico">
<title>OSEP_scratch 1131217</title>
<title>OSEP_scratch 1131228</title>

</head>
<body>
Expand Down
129 changes: 91 additions & 38 deletions app/lib.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -439491,10 +439491,21 @@ var Scratch3PushNotifyAPI = /*#__PURE__*/function () {
switch (_context.prev = _context.next) {
case 0:
this.payload.content = args.CONTENT;
_context.prev = 1;

if (!(this.payload.apikey === '' || this.payload.content === '')) {
_context.next = 5;
break;
}

alert(msg.TokenNull);
_context.next = 27;
break;

case 5:
_context.prev = 5;
this.payload.message = args.MESSAGE;
console.log('Sending message:', this.payload);
_context.next = 6;
_context.next = 10;
return fetch("https://xdroid.net/api/message?k=".concat(this.payload.apikey, "&t=").concat(this.payload.title, "&c=").concat(this.payload.content, "&u=").concat(this.payload.url), {
method: 'get'
/*headers: {
Expand All @@ -439507,43 +439518,43 @@ var Scratch3PushNotifyAPI = /*#__PURE__*/function () {

});

case 6:
case 10:
response = _context.sent;
_context.next = 9;
_context.next = 13;
return response.json();

case 9:
case 13:
result = _context.sent;
console.log('API Response:', result);

if (result.ok) {
_context.next = 14;
_context.next = 18;
break;
}

console.error('Telegram API Error:', result.description);
return _context.abrupt("return");

case 14:
case 18:
// 成功發送後再清空
this.payload.apikey = '';
this.payload.content = '';
this.payload.title = '';
this.payload.url = '';
_context.next = 23;
_context.next = 27;
break;

case 20:
_context.prev = 20;
_context.t0 = _context["catch"](1);
case 24:
_context.prev = 24;
_context.t0 = _context["catch"](5);
console.error('Error sending message:', _context.t0);

case 23:
case 27:
case "end":
return _context.stop();
}
}
}, _callee, this, [[1, 20]]);
}, _callee, this, [[5, 24]]);
}));

function sendmessage(_x) {
Expand Down Expand Up @@ -439598,7 +439609,7 @@ var setapikey = {
};
var settitle = {
'en': 'Set title text [TITLE]',
'zh-tw': '設定抬頭[TITLE]'
'zh-tw': '設定標題[TITLE]'
};
var TokenNull = {
'en': 'Token or Message is null',
Expand Down Expand Up @@ -446061,8 +446072,7 @@ var Scratch3TelegramBot = /*#__PURE__*/function () {
token: '',
message: '',
imageFile: '',
chat_id: '',
sticker: ''
chat_id: ''
};
this.exec = 'https://script.google.com/macros/s/AKfycbyPMsaLgEEcia39_vcK1AmSGfpAi2YViAUcZFMbmKdYJ5niqDVui9Rgb4241Zdwca5d/exec';
}
Expand All @@ -446083,6 +446093,16 @@ var Scratch3TelegramBot = /*#__PURE__*/function () {
opcode: 'checkOut',
blockType: BlockType.COMMAND,
text: msg.checkOut[the_locale]
}, {
opcode: 'checkchatid',
blockType: BlockType.COMMAND,
text: msg.checkchatid[the_locale],
arguments: {
TOKEN: {
type: ArgumentType.STRING,
defaultValue: ' '
}
}
}, {
opcode: 'gettoken',
blockType: BlockType.COMMAND,
Expand Down Expand Up @@ -446120,21 +446140,32 @@ var Scratch3TelegramBot = /*#__PURE__*/function () {
text: msg.Sendsticker[the_locale],
arguments: {
STICKER: {
type: ArgumentType.NUMBER,
type: ArgumentType.STRING,
defaultValue: '😀',
menu: 'sticker_list'
}
}
}, {
opcode: 'sendmessage',
opcode: 'setsendtext',
blockType: BlockType.COMMAND,
text: msg.SendMessage[the_locale],
text: msg.setsendtext[the_locale],
arguments: {
MESSAGE: {
TEXT: {
type: ArgumentType.STRING,
defaultValue: ' '
}
}
}, {
opcode: 'sendmessage',
blockType: BlockType.COMMAND,
text: msg.SendMessage[the_locale]
/*arguments: {
MESSAGE: {
type: ArgumentType.STRING,
defaultValue: ' ',
}
},*/

}],
menus: {
sticker_list: {
Expand All @@ -446150,6 +446181,12 @@ var Scratch3TelegramBot = /*#__PURE__*/function () {
value: function checkOut() {
window.open('https://unicode.org/emoji/charts/full-emoji-list.html');
}
}, {
key: "checkchatid",
value: function checkchatid(args) {
apikey = args.TOKEN;
window.open('https://api.telegram.org/bot' + apikey + '/getUpdates');
}
}, {
key: "get_chat_id",
value: function get_chat_id(args) {
Expand All @@ -446161,6 +446198,12 @@ var Scratch3TelegramBot = /*#__PURE__*/function () {
this.payload.token = args.TOKEN;
console.log(this.payload.token);
}
}, {
key: "setsendtext",
value: function setsendtext(args) {
this.payload.message = this.payload.message + args.TEXT;
console.log('message=', this.payload.message);
}
}, {
key: "sendmessage",
value: function () {
Expand All @@ -446171,56 +446214,56 @@ var Scratch3TelegramBot = /*#__PURE__*/function () {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
this.payload.message = args.MESSAGE;
//this.payload.message = args.MESSAGE;
console.log('Sending message:', this.payload);
_context.next = 5;
_context.next = 4;
return fetch("https://api.telegram.org/bot".concat(this.payload.token, "/sendMessage"), {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
chat_id: this.payload.chat_id,
text: this.payload.sticker + this.payload.message
text: this.payload.message
})
});

case 5:
case 4:
response = _context.sent;
_context.next = 8;
_context.next = 7;
return response.json();

case 8:
case 7:
result = _context.sent;
console.log('API Response:', result);

if (result.ok) {
_context.next = 13;
_context.next = 12;
break;
}

console.error('Telegram API Error:', result.description);
return _context.abrupt("return");

case 13:
case 12:
// 成功發送後再清空
this.payload.message = '';
this.payload.sticker = '';
this.payload.imageFile = '';
_context.next = 21;
_context.next = 20;
break;

case 18:
_context.prev = 18;
case 17:
_context.prev = 17;
_context.t0 = _context["catch"](0);
console.error('Error sending message:', _context.t0);

case 21:
case 20:
case "end":
return _context.stop();
}
}
}, _callee, this, [[0, 18]]);
}, _callee, this, [[0, 17]]);
}));

function sendmessage(_x) {
Expand Down Expand Up @@ -446301,7 +446344,7 @@ var Scratch3TelegramBot = /*#__PURE__*/function () {
}, {
key: "sendsticker",
value: function sendsticker(args) {
this.payload.sticker = this.payload.sticker + args.STICKER;
this.payload.message = this.payload.message + args.STICKER;
} // end of block handlers

}, {
Expand Down Expand Up @@ -446335,29 +446378,39 @@ module.exports = Scratch3TelegramBot;
/*!************************************************************************************!*\
!*** ./node_modules/scratch-vm/src/extensions/scratch3_telegrambot/translation.js ***!
\************************************************************************************/
/*! exports provided: checkOut, Token, SendMessage, TokenNull, Sendsticker, chat_id, SendImageFile */
/*! exports provided: checkOut, checkchatid, Token, SendMessage, setsendtext, TokenNull, Sendsticker, chat_id, SendImageFile */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "checkOut", function() { return checkOut; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "checkchatid", function() { return checkchatid; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Token", function() { return Token; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SendMessage", function() { return SendMessage; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setsendtext", function() { return setsendtext; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "TokenNull", function() { return TokenNull; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Sendsticker", function() { return Sendsticker; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "chat_id", function() { return chat_id; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SendImageFile", function() { return SendImageFile; });
var checkOut = {
'en': 'check out Line sticker definitions',
'en': 'check out sticker definitions',
'zh-tw': '查閱表情主題與代號'
};
var checkchatid = {
'en': 'check out chat id . TOEN text:[TOKEN]',
'zh-tw': '查閱聊天室id 你的權杖:[TOKEN]'
};
var Token = {
'en': 'token text [TOKEN]',
'zh-tw': '權杖[TOKEN]'
};
var SendMessage = {
'en': 'send the message [MESSAGE]',
'zh-tw': '送出訊息[MESSAGE]'
'en': 'send the message',
'zh-tw': '送出訊息'
};
var setsendtext = {
'en': 'set send the message [TEXT]',
'zh-tw': '設定送出訊息[TEXT]'
};
var TokenNull = {
'en': 'Token or Message is null',
Expand Down
2 changes: 1 addition & 1 deletion app/lib.min.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit bdf53bb

Please sign in to comment.