Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //MH+ presents, super simple Online tracking with discord webhook
- //join us! => https://discord.link/SLguru
- //
- // 参考:https://discord.com/developers/docs/resources/webhook
- //設定必須 (modify required) ///////////////////////////////////////////////////
- string AvatarNAME = "";
- string WEBHOOK_URL = "";
- integer Time_Offset = 9; //日本時間(JST)
- ////////////////////////////////////////////////////////////////////////////////
- // こんな感じでURLが払い出されます
- // WEBHOOK_URL =
- // |----------------------------------------------------------------------------------------------------------------------|
- // https://discord.com/api/webhooks/123456789012345678/abcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcd
- // |~~~~~~~~~~~~~~~~~~|
- // |WEBHOOK_CHANNEL = |
- // |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // |WEBHOOK_TOKEN =
- ////////////////////////////////////////////////////////////////////////////////
- string User_NAME = "";
- string User_DISP = "";
- key User_UUID;
- key QUERY_KEY;
- key REQUEST_KEY;
- integer FLG_ONLINE;
- //
- // from : http://wiki.secondlife.com/wiki/GetTimestampOffset
- string sbGetTimestamp(integer intOffset) {
- // Start with December for purposes of wrapping
- list lstDays = [31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
- string strTimestamp = llGetTimestamp();
- list lstTime = llParseString2List(strTimestamp, ["-", ":", ".", "T"], []);
- integer intYear = llList2Integer(lstTime, 0);
- integer intMonth = llList2Integer(lstTime, 1);
- integer intDay = llList2Integer(lstTime, 2);
- integer intHour = llList2Integer(lstTime, 3);
- string strYear;
- string strMonth;
- string strDay;
- string strHour;
- if (intOffset == 0) { return strTimestamp; }
- if (intOffset < -24 || intOffset > 24) {
- intOffset = ((integer)llGetWallclock() - (integer)llGetGMTclock()) / 3600;
- }
- intHour+= intOffset;
- // Add a day to February in leap years
- if (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0)) {
- lstDays = llListReplaceList(lstDays, [29], 2, 2);
- }
- if (intOffset < 0) {
- if (intHour < 0) {
- intHour+= 24;
- --intDay;
- }
- if (intDay < 1) {
- intDay = llList2Integer(lstDays, --intMonth);
- }
- if (intMonth < 1) {
- intMonth = 12;
- --intYear;
- }
- }
- if (intOffset > 0) {
- if (intHour > 23) {
- intHour-= 24;
- ++intDay;
- }
- if (intDay > llList2Integer(lstDays, intMonth)) {
- intDay = 1;
- ++intMonth;
- }
- if (intMonth > 12) {
- intMonth = 1;
- ++intYear;
- }
- }
- strYear = (string)intYear;
- strMonth = (string)intMonth;
- strDay = (string)intDay;
- strHour = (string)intHour;
- if (llStringLength(strMonth) < 2) { strMonth = "0" + strMonth; }
- if (llStringLength(strDay) < 2) { strDay = "0" + strDay; }
- if (llStringLength(strHour) < 2) { strHour = "0" + strHour; }
- return
- strYear + "-" +
- strMonth + "-" +
- strDay + " " +
- strHour + ":" +
- llList2String(lstTime, 4) + ":" +
- llList2String(lstTime, 5) ;//+ "." +
- //llList2String(lstTime, 6) + "Z";
- // Obviously this isn't really Z time anymore, but I left it there in case there
- // are scripts expecting it.
- }
- default{//ユーザー名から正規のNAMEとUUIDと表示名を取得
- on_rez(integer i){
- llResetScript();
- }
- state_entry(){
- //アバター名があれば
- if(AvatarNAME != ""){
- //アバター名から取得
- User_NAME = "";
- User_DISP = "";
- User_UUID = NULL_KEY;
- QUERY_KEY = llRequestUserKey(AvatarNAME);
- }else{
- llOwnerSay("スクリプトを編集し、対象のアバター名(AvatarNAME)を設定してください。");
- }
- }
- dataserver(key requestID, string data) {
- if(requestID == QUERY_KEY){
- if(User_UUID == NULL_KEY){
- if((key)data){
- User_UUID = (key)data;
- llOwnerSay("アバターのUUID取得 OK : " + (string)User_UUID);
- QUERY_KEY = llRequestUsername(User_UUID);
- }else{
- llOwnerSay("このグリッドには存在しないアバターです。 : " + AvatarNAME);
- }
- }else if(User_NAME == ""){
- if(data != ""){
- User_NAME = data;
- }else{
- User_NAME = AvatarNAME;
- }
- llOwnerSay("アバターの正規名取得 OK : " + User_NAME);
- QUERY_KEY = llRequestDisplayName(User_UUID);
- }else if(User_DISP == ""){
- if(data != ""){
- User_DISP = data;
- }else{
- User_DISP = AvatarNAME;
- }
- llOwnerSay("アバターの表示名取得 OK : " + User_DISP);
- state RUN;
- }
- }
- }
- }
- state RUN{//対象のUUIDからオンライン状態チェック
- state_entry(){
- //URLがあれば
- if(WEBHOOK_URL != ""){
- FLG_ONLINE = 999;
- //タイマー開始 (36秒よりも短くしても無駄ですのでやめましょう)
- llSetTimerEvent(36.0);
- llOwnerSay("チェック動作を開始します。");
- llOwnerSay("停止させる場合はスクリプトの実行そのものを停止してください。");
- }else{
- llOwnerSay("スクリプトを編集し、DiscordのHook URL(WEBHOOK_URL)を設定してください。");
- }
- }
- timer(){
- QUERY_KEY = llRequestAgentData(User_UUID,DATA_ONLINE);
- }
- dataserver(key request_id, string data){
- if(request_id == QUERY_KEY){
- integer nowSTA = (integer)data;
- if(FLG_ONLINE != nowSTA){
- FLG_ONLINE = nowSTA;
- //アイコンとユーザー名を上書きする
- list json = [
- "username", User_DISP + " (" + User_NAME + ")",
- "content", llList2String(["**now Off Line** :sleeping:","**now On Line** :smiley:"],FLG_ONLINE) +
- " " + sbGetTimestamp(Time_Offset),
- "avatar_url", "https://my-secondlife-agni.akamaized.net/users/" + User_NAME + "/thumb_sl_image.png"
- ];
- //画像が未登録の場合表示エラーになるけれどWEBHOOKで定義したアイコンになる
- //?wait=は省略時false エラー時の情報取得用など向け。書き込んだ内容が返却される
- //REQUEST_KEY = llHTTPRequest(WEBHOOK_URL + "?wait=true",
- REQUEST_KEY = llHTTPRequest(WEBHOOK_URL,
- [
- HTTP_METHOD, "POST",
- HTTP_MIMETYPE, "application/json",
- HTTP_VERIFY_CERT,TRUE,
- HTTP_VERBOSE_THROTTLE, TRUE,
- HTTP_PRAGMA_NO_CACHE, TRUE
- ], llList2Json(JSON_OBJECT, json));
- }
- QUERY_KEY = NULL_KEY;
- }
- }
- http_response(key request_id, integer status, list metadata, string body){
- if(REQUEST_KEY == request_id){
- if(status < 200 || status > 206) llOwnerSay("status = " + (string)status + " ;body = " + body);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement