-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin_init.azr
307 lines (297 loc) · 8.61 KB
/
plugin_init.azr
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
//******************************************************************************
// グローバル変数
//******************************************************************************
string sender;
string sender_saved;
string hwnd;
string ownedSSTPid;
string selfName;
string selfScreenName;
int balloonWidth;
array arHome;
array arHomeNext;
array arMentions;
array arMentionsNext;
array arLikes;
array arLocalTimeline;
string sHome;
string sMentions;
string sLikes;
string sMessages;
string sLocalTimeline;
dict dIconPath;
dict dEmojiPath;
dict dEmojiPathAlpha;
string postidToReply;
string reservedScript;
int isInit;
int BALLOON_WIDTH_MIN = 100;
//******************************************************************************
// プラグイン初期化処理
//******************************************************************************
loadPlugin()
{
//デフォルトサーバーをセット
if (dictSaveData["server_url"] == nil)
dictSaveData += $("server_url", getDefaultMastodonServerURL());
// reservedScriptを設定してOnGhostBootでnotifypluginを実行
// sender, hwnd, ownedSSTPidを取得して後続のDSSTPを実行できるようにする
isInit = 1;
reservedScript = "\C\![notifyplugin," + pluginid() + ",OnMenuExec]\e";
}
TH_LoadPlugin()
{
sender_saved = sender;
// 定期投稿取得タイマセット
string s = setTimerraise();
if (s != "")
{
// 初回呼び出しは文字コードが正しく認識されない & logに記録されない (YAYAのバグ?)
dict d = _saorirequest("yaya", "DSSTP.SendDummyRequestToYAYA");
speakBySSTP("\C" + s + "\e", hwnd, ownedSSTPid);
_sleep(1);
}
// 認証
TH_VerifyAccount();
_sleep(1);
// 投稿全取得
TH_GetAllToots();
_sleep(1);
// PLUGINの更新を確認
TH_CheckUpdatePlugin();
}
//------------------------------------------------------------------------------
// PLUGINの更新を確認
TH_CheckUpdatePlugin()
{
string url = homeurl() + "readme.txt";
array arJson = httpget(url, "utf8");
if (_aryvn(arJson) == 0)
return;
string versionNext;
string reg = "^.*[0-9]+-[0-9]+-[0-9]+ Ver([0-9]\.[0-9]) .*$";
for (int i = 0; i < _aryvn(arJson); i++)
{
if (_regex_match(arJson[i], reg))
versionNext = _regex_search(arJson[i], reg)[1];
}
string versionNow = _strsplit(version(), "/")[1];
if ((0.5 * versionNow) < (0.5 * versionNext))
{
speakBySSTP("\C\![raiseplugin," + pluginid() + ",OnShowPopUpUpdate," + versionNext + "]\e");
}
}
string OnShowPopUpUpdate(dict ref)
{
string versionNext = ref["Reference0"];
string title = pluginname() + " 更新通知";
string mes = pluginnameen() + "/" + versionNext + "がリリースされています";
string s = showErrorMessage(title, mes, "info") + "\e";
dictOptionalHeader["target"] = sender;
dictOptionalHeader["script_option"] = "nobreak,notranslate";
dictOptionalHeader["marker"] = version();
return s;
}
string openUpdateMenu()
{
string s;
s += "\_l[0,0]■" + pluginnameen() + " update menu\_l[0,30]";
s += menuItem("配布ページをブラウザで開く",
{"UpdatePlugin", "OpenURL"}, 0);
s += menuItem("ネットワーク更新を実行する",
{"UpdatePlugin", "NetworkUpdate"}, 100);
s += menuItem("キャンセル",
{"Menu_CANCEL"}, 200);
s = "\0\_q" + s + "\_q\e";
dictOptionalHeader["target"] = sender;
dictOptionalHeader["script_option"] = "nobreak,notranslate";
dictOptionalHeader["marker"] = version();
return s;
}
//-------------------------------------------------------
// 選択肢:UpdatePlugin
// 内容 :プラグイン更新関連処理実行
//-------------------------------------------------------
string UpdatePlugin(dict ref)
{
string s;
switch (ref["Reference2"])
{
case "OpenURL":
s = "\C\0\_q \_q\![open,browser," + craftmanurl() + "]\e";
break;
case "NetworkUpdate":
s = "\![updateother,--plugin=" + pluginname() + "]\e";
break;
default:
break;
}
dictOptionalHeader["target"] = sender;
dictOptionalHeader["script_option"] = "nobreak,notranslate";
dictOptionalHeader["marker"] = version();
return s;
}
//******************************************************************************
// プラグイン後始末処理
//******************************************************************************
unloadPlugin()
{
// アイコンファイル削除
array a = _fenum("icon")["file"];
for (int i = 0; a[i] != nil; i++)
{
if (_regex_match(a[i], "^(icon|emoji|image)_.*\.png$"))
_fdelete("icon\\" + a[i]);
}
}
//******************************************************************************
// PLUGIN Event
//******************************************************************************
//-------------------------------------------------------
// 選択肢
//-------------------------------------------------------
string OnChoiceSelect(dict ref)
{
return _fncstr(ref["Reference0"], ref);
}
string OnChoiceSelectEx(dict ref)
{
return _fncstr(ref["Reference1"], ref);
}
//-------------------------------------------------------
// アンカー
//-------------------------------------------------------
string OnAnchorSelect(dict ref)
{
string id = ref["Reference0"];
string regurl = "^(https?://|www\.)[-_.!~*'()a-zA-Z0-9;/?:@&=+$,%#]+$";
if (_regex_match(id, regurl)) {
if (_regex_match(id, "^www\..+$")) {
id = "http://" + id;
}
string url = escapeText(id);
return "\C\![open,browser," + url + "]\_l[0,0]\_q \_q\e";
} else {
return _fncstr(id, ref);
}
}
//-------------------------------------------------------
// ユーザ入力
//-------------------------------------------------------
string OnUserInput(dict ref)
{
return _fncstr("Input" + ref["Reference0"], ref);
}
//-------------------------------------------------------
// イベント:OnExecuteHTTPComplete
// 内容 :\![execute,http-post]成功
//-------------------------------------------------------
string OnExecuteHTTPComplete(dict ref)
{
if (ref["Reference0"] != "post")
return "";
string s;
switch (ref["Reference1"])
{
case "MastodonPost":
_create_thread("TH_UpdateHome");
s = "\![set,balloontimeout,0]\0\b[2]\_q■updating...\_q\e";
break;
case "MastodonAddStar":
// 本来、保存してあるログを精査してfavのON/OFFを切り替える作業が入る
// が、面倒なので全入れ替え
_create_thread("TH_UpdateAll");
s = "\![set,balloontimeout,0]\0\b[2]\_q■updating...\_q\e";
break;
default:
break;
}
dictOptionalHeader["target"] = sender;
dictOptionalHeader["script_option"] = "nobreak,notranslate";
dictOptionalHeader["marker"] = version();
return s;
}
//-------------------------------------------------------
// イベント:OnExecuteHTTPFailure
// 内容 :\![execute,http-post]失敗
//-------------------------------------------------------
string OnExecuteHTTPFailure(dict ref)
{
if (ref["Reference0"] != "post")
return "";
string s = showErrorMessage(pluginname(), "failed to update post.", "warning") + "\e";
dictOptionalHeader["target"] = sender;
dictOptionalHeader["script_option"] = "nobreak,notranslate";
dictOptionalHeader["marker"] = version();
return s;
}
//-------------------------------------------------------
// イベント:OnTrayBalloonClick
//-------------------------------------------------------
string OnTrayBalloonClick(dict ref)
{
string title = ref["Reference0"];
string s;
if (_strstr(title, pluginname() + " 新着") >= 0)
{
if (balloonWidth < 100)
return "\![raiseplugin," + pluginid() + ",OnMenuExec]\e";
else
return showHomeTL();
}
if (_strstr(title, pluginname() + " 更新通知") >= 0)
{
return openUpdateMenu();
}
return "";
}
//-------------------------------------------------------
// イベント:OnGhostBoot(load時のみ予約Scriptを再生するために使用)
//-------------------------------------------------------
string OnGhostBoot(dict ref)
{
if (reservedScript != "")
{
string s = reservedScript;
reservedScript = "";
dictOptionalHeader["script_option"] = "nobreak,notranslate";
dictOptionalHeader["marker"] = version();
return s;
}
return "";
}
//******************************************************************************
// 固有設定
//******************************************************************************
string getDefaultMastodonServerURL()
{
return "https://ukadon.shillest.net/";
}
string getPluginOAuthURL()
{
return "http://nikolat.starfree.jp/ukadonyu/";
}
string craftmanurl()
{
return "http://nikolat.starfree.jp/ukadonyu/";
}
string homeurl()
{
return "https://raw.githubusercontent.com/nikolat/ukadonyu/main/";
}
string pluginid()
{
return "ba24f930-4b68-11ec-8072-0800200c9a66";
}
string pluginnameen()
{
return "ukadonyu";
}
string pluginname()
{
return "うかどんゅう";
}
string version()
{
return "ukadonyu/2.2";
}