Skip to content

Instantly share code, notes, and snippets.

@Eotones
Last active November 1, 2022 09:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Eotones/caa90bb41f1992960aeb38c2600f0232 to your computer and use it in GitHub Desktop.
Save Eotones/caa90bb41f1992960aeb38c2600f0232 to your computer and use it in GitHub Desktop.
Nightbot自訂Twitch指令 - 美金和台幣匯率換算 (下方有新增其他Nightbot自訂指令)

Nightbot自訂Twitch指令 - 美金和台幣匯率換算

USD 轉 TWD

Twitch聊天室輸入指令新增:

!commands add !usd $(eval const n=parseFloat('$(query)');if(!isNaN(n)){const api = $(urlfetch json https://tw.rter.info/capi.php); api.error || (!api.USDTWD.Exrate) ? '查無資料' : `${n} USD = ${(n*api.USDTWD.Exrate).toFixed(2)} TWD (source: RTER)`;}else{'請在指令後面輸入數字'})

如果要編輯已存在指令的話要把!commands add !usd 的部份改成!editcom !usd 就可以了

或是在Nightbot後台新增:

指令名:
!usd
指令內容:
$(eval const n=parseFloat('$(query)');if(!isNaN(n)){const api = $(urlfetch json https://tw.rter.info/capi.php); api.error || (!api.USDTWD.Exrate) ? '查無資料' : `${n} USD = ${(n*api.USDTWD.Exrate).toFixed(2)} TWD (source: RTER)`;}else{'請在指令後面輸入數字'})

結果

輸入:
!usd 100
輸出:
100 USD = 2776.45 TWD

TWD 轉 USD

Twitch聊天室輸入指令新增:

!commands add !twd $(eval const n=parseFloat('$(query)');if(!isNaN(n)){const api = $(urlfetch json https://tw.rter.info/capi.php); api.error || (!api.USDTWD.Exrate) ? '查無資料' : `${n} TWD = ${(n/api.USDTWD.Exrate).toFixed(2)} USD (source: RTER)`;}else{'請在指令後面輸入數字'})

如果要編輯已存在指令的話要把!commands add !twd 的部份改成!editcom !twd 就可以了

或是在Nightbot後台新增:

指令名:
!twd
指令內容:
$(eval const n=parseFloat('$(query)');if(!isNaN(n)){const api = $(urlfetch json https://tw.rter.info/capi.php); api.error || (!api.USDTWD.Exrate) ? '查無資料' : `${n} TWD = ${(n/api.USDTWD.Exrate).toFixed(2)} USD (source: RTER)`;}else{'請在指令後面輸入數字'})

結果

輸入:
!twd 1000
輸出:
1000 TWD = 36.02 USD

小知識

  • Nightbot主要是使用在Twitch或Youtube聊天室的Bot
  • Nightbot後台連接上Discord的話能讓Discord使用Twitch或Youtube上設定過的相同指令
  • RTER.info API提供的幣值有很多種,如果要轉換其他地區幣值的話可以自己找API規則來改寫
  • 幣別
    • USD 美國(美金)
    • EUR 歐元區(歐元)
    • JPY 日本(日幣)
    • HKD 香港(港幣)
    • GBP 英國(英鎊)
    • CHF 瑞士(瑞士法郎)
    • CNY 中國(人民幣)
    • CNH 中國(離岸人民幣)
    • KRW 南韓(韓元)
    • AUD 澳大利亞(澳幣)
    • NZD 紐西蘭(紐幣)
    • SGD 新加坡(新加坡幣)
    • THB 泰國(泰銖)
    • SEK 瑞典(瑞典幣)
    • MYR 馬來西亞(馬來幣)
    • CAD 加拿大(加拿大幣)
    • VND 越南(越南盾)
    • MOP 澳門(澳門幣)
    • PHP 菲律賓(菲律賓比索)
    • INR 印度(印度盧比)
    • IDR 印尼(印尼盾)
    • DKK 丹麥(丹麥克朗)
    • ZAR 南非(南非蘭特)
    • MXN 墨西哥(墨西哥披索)
    • TRY 土耳其(土耳其里拉)
    • TWD 台灣(台幣)

參考資料

範例

!commands add !usd $(eval const n=parseFloat('$(query)');if(!isNaN(n)){const api = $(urlfetch json https://tw.rter.info/capi.php); api.error || (!api.USDTWD.Exrate) ? '查無資料' : `${n} USD = ${(n*api.USDEUR.Exrate).toFixed(2)} EUR = ${(n*api.USDTWD.Exrate).toFixed(2)} TWD = ${(n*api.USDCNY.Exrate).toFixed(2)} CNY = ${(n*api.USDJPY.Exrate).toFixed(2)} JPY = ${(n*api.USDKRW.Exrate).toFixed(2)} KRW (source: RTER)`;}else{'請在指令後面輸入數字'})

!commands add !twd $(eval const n=parseFloat('$(query)');if(!isNaN(n)){const api = $(urlfetch json https://tw.rter.info/capi.php); api.error || (!api.USDTWD.Exrate) ? '查無資料' : `${n} 台幣 = ${(n/api.USDTWD.Exrate).toFixed(2)} 美金 (source: RTER)`;}else{'請在指令後面輸入數字'})

!commands add !krw $(eval const n=parseFloat('$(query)');if(!isNaN(n)){const api = $(urlfetch json https://tw.rter.info/capi.php); api.error || (!api.USDTWD.Exrate) ? '查無資料' : `${n} 韓元 = ${(n/api.USDKRW.Exrate).toFixed(5)} 美金 = ${(n/api.USDKRW.Exrate*api.USDTWD.Exrate).toFixed(3)} 台幣 (source: RTER)`;}else{'請在指令後面輸入數字'})
!commands add !jpy $(eval const n=parseFloat('$(query)');if(!isNaN(n)){const api = $(urlfetch json https://tw.rter.info/capi.php); api.error || (!api.USDTWD.Exrate) ? '查無資料' : `${n} 日幣 = ${(n/api.USDJPY.Exrate).toFixed(3)} 美金 = ${(n/api.USDJPY.Exrate*api.USDTWD.Exrate).toFixed(2)} 台幣 (source: RTER)`;}else{'請在指令後面輸入數字'})

!commands add !cny $(eval const n=parseFloat('$(query)');if(!isNaN(n)){const api = $(urlfetch json https://tw.rter.info/capi.php); api.error || (!api.USDTWD.Exrate) ? '查無資料' : `${n} 人民幣 = ${(n/api.USDCNY.Exrate).toFixed(2)} 美金 = ${(n/api.USDCNY.Exrate*api.USDTWD.Exrate).toFixed(2)} 台幣 (source: RTER)`;}else{'請在指令後面輸入數字'})
!commands add !hkd $(eval const n=parseFloat('$(query)');if(!isNaN(n)){const api = $(urlfetch json https://tw.rter.info/capi.php); api.error || (!api.USDTWD.Exrate) ? '查無資料' : `${n} 港幣  = ${(n/api.USDHKD.Exrate).toFixed(2)} 美金 = ${(n/api.USDHKD.Exrate*api.USDTWD.Exrate).toFixed(2)} 台幣 (source: RTER)`;}else{'請在指令後面輸入數字'})
!commands add !mop $(eval const n=parseFloat('$(query)');if(!isNaN(n)){const api = $(urlfetch json https://tw.rter.info/capi.php); api.error || (!api.USDTWD.Exrate) ? '查無資料' : `${n} 澳門幣 = ${(n/api.USDMOP.Exrate).toFixed(2)} 美金 = ${(n/api.USDMOP.Exrate*api.USDTWD.Exrate).toFixed(2)} 台幣 (source: RTER)`;}else{'請在指令後面輸入數字'})

!commands add !sgd $(eval const n=parseFloat('$(query)');if(!isNaN(n)){const api = $(urlfetch json https://tw.rter.info/capi.php); api.error || (!api.USDTWD.Exrate) ? '查無資料' : `${n} 新加坡幣 = ${(n/api.USDSGD.Exrate).toFixed(2)} 美金= ${(n/api.USDSGD.Exrate*api.USDTWD.Exrate).toFixed(2)} 台幣 (source: RTER)`;}else{'請在指令後面輸入數字'})
!commands add !myr $(eval const n=parseFloat('$(query)');if(!isNaN(n)){const api = $(urlfetch json https://tw.rter.info/capi.php); api.error || (!api.USDTWD.Exrate) ? '查無資料' : `${n} 馬來幣 = ${(n/api.USDMYR.Exrate).toFixed(2)} 美金= ${(n/api.USDMYR.Exrate*api.USDTWD.Exrate).toFixed(2)} 台幣 (source: RTER)`;}else{'請在指令後面輸入數字'})

如果要編輯已存在指令的話要把!commands add 的部份改成!editcom 就可以了

@Eotones
Copy link
Author

Eotones commented Sep 28, 2021

補充其他指令:

nightbot從後台連接discord之後
也能在discord使用twitch上的指令

以下指令主要是為了方便discord使用

顯示維基百科第一個搜尋搜尋結果的標題和連結

!wiki Github
!wiki-en Github

中文維基百科

!commands add !wiki 維基百科: $(eval const api=$(urlfetch json https://zh.wikipedia.org/w/api.php?format=json&action=opensearch&search=$(querystring)); if(api.error || !api[1][0]){'Please add a query to the search'}else{let a=api[1][0],b=decodeURIComponent(api[3][0]); `${a} - || ${b} ||`})

英文維基百科

!commands add !wiki-en Wikipedia: $(eval const api=$(urlfetch json https://en.wikipedia.org/w/api.php?format=json&action=opensearch&search=$(querystring)); if(api.error || !api[1][0]){'Please add a query to the search'}else{let a=api[1][0],b=decodeURIComponent(api[3][0]); `${a} - || ${b} ||`})

@Eotones
Copy link
Author

Eotones commented Oct 13, 2021

Google翻譯

感謝twitch_aili提供

  • 2021/12/4修正句子過長被截斷的問題
!auto2tw
$(eval let r=''; const res=$(urlfetch json https://translate.google.com/translate_a/single?client=gtx&dt=t&dj=1&ie=UTF-8&sl=auto&tl=zh-TW&q=$(querystring)); if(res.error){'error'}else{for(let i=0;i<res['sentences'].length;i++){r+=res['sentences'][i]['trans'];}`[${res['ld_result']['extended_srclangs'][0]} -> tw] @$(user) : ${r}`})
!auto2cn
$(eval let r=''; const res=$(urlfetch json https://translate.google.com/translate_a/single?client=gtx&dt=t&dj=1&ie=UTF-8&sl=auto&tl=zh-CN&q=$(querystring)); if(res.error){'error'}else{for(let i=0;i<res['sentences'].length;i++){r+=res['sentences'][i]['trans'];}`[${res['ld_result']['extended_srclangs'][0]} -> cn] @$(user) : ${r}`})
!auto2en
$(eval let r=''; const res=$(urlfetch json https://translate.google.com/translate_a/single?client=gtx&dt=t&dj=1&ie=UTF-8&sl=auto&tl=en&q=$(querystring)); if(res.error){'error'}else{for(let i=0;i<res['sentences'].length;i++){r+=res['sentences'][i]['trans'];}`[${res['ld_result']['extended_srclangs'][0]} -> en] @$(user) : ${r}`})
!auto2ja
$(eval let r=''; const res=$(urlfetch json https://translate.google.com/translate_a/single?client=gtx&dt=t&dj=1&ie=UTF-8&sl=auto&tl=ja&q=$(querystring)); if(res.error){'error'}else{for(let i=0;i<res['sentences'].length;i++){r+=res['sentences'][i]['trans'];}`[${res['ld_result']['extended_srclangs'][0]} -> ja] @$(user) : ${r}`})

!ja2en
$(eval let r=''; const res=$(urlfetch json https://translate.google.com/translate_a/single?client=gtx&dt=t&dj=1&ie=UTF-8&sl=ja&tl=en&q=$(querystring)); if(res.error){'error'}else{for(let i=0;i<res['sentences'].length;i++){r+=res['sentences'][i]['trans'];}`[ja -> en] @$(user) : ${r}`})
!zh2en
$(eval let r=''; const res=$(urlfetch json https://translate.google.com/translate_a/single?client=gtx&dt=t&dj=1&ie=UTF-8&sl=zh-TW&tl=en&q=$(querystring)); if(res.error){'error'}else{for(let i=0;i<res['sentences'].length;i++){r+=res['sentences'][i]['trans'];}`[zh -> en] @$(user) : ${r}`})
!ja2tw
$(eval let r=''; const res=$(urlfetch json https://translate.google.com/translate_a/single?client=gtx&dt=t&dj=1&ie=UTF-8&sl=ja&tl=zh-TW&q=$(querystring)); if(res.error){'error'}else{for(let i=0;i<res['sentences'].length;i++){r+=res['sentences'][i]['trans'];}`[ja -> tw] @$(user) : ${r}`})
!ja2cn
$(eval let r=''; const res=$(urlfetch json https://translate.google.com/translate_a/single?client=gtx&dt=t&dj=1&ie=UTF-8&sl=ja&tl=zh-CN&q=$(querystring)); if(res.error){'error'}else{for(let i=0;i<res['sentences'].length;i++){r+=res['sentences'][i]['trans'];}`[ja -> cn] @$(user) : ${r}`})
!en2tw
$(eval let r=''; const res=$(urlfetch json https://translate.google.com/translate_a/single?client=gtx&dt=t&dj=1&ie=UTF-8&sl=en&tl=zh-TW&q=$(querystring)); if(res.error){'error'}else{for(let i=0;i<res['sentences'].length;i++){r+=res['sentences'][i]['trans'];}`[en -> tw] @$(user) : ${r}`})
!en2cn
$(eval let r=''; const res=$(urlfetch json https://translate.google.com/translate_a/single?client=gtx&dt=t&dj=1&ie=UTF-8&sl=en&tl=zh-CN&q=$(querystring)); if(res.error){'error'}else{for(let i=0;i<res['sentences'].length;i++){r+=res['sentences'][i]['trans'];}`[en -> cn] @$(user) : ${r}`})

常用語言選項

  • auto=自動偵測語言 (有可能會偵測錯語言)
  • en=英文
  • zh-TW=繁中
  • zh-CN=簡中
  • ja=日文
  • ko=韓文

@Eotones
Copy link
Author

Eotones commented Nov 12, 2021

中油油價

指令語法

!油價
$(eval const res=$(urlfetch json https://www.cpc.com.tw//GetOilPriceJson.aspx?type=TodayOilPriceString); (res.error)?'error':`中油油價(台幣/公升): [92:${res['sPrice1']}] [95:${res['sPrice2']}] [98:${res['sPrice3']}] [超柴:${res['sPrice5']}] 實施時間:${res['LPGdate']}`;)

顯示結果:

中油油價(台幣/公升): [92:30.0] [95:31.5] [98:33.5] [超柴:28.1] 實施時間:11月8日

@Eotones
Copy link
Author

Eotones commented Dec 3, 2021

取得Chrome最新版號

指令語法

!chrome
$(eval const res=$(urlfetch json https://omahaproxy.appspot.com/all.json); if(res.error){'error'}else{for(let i=0;i<res.length;i++){if(res[i].os==='win64'){for(let j=0;j<res[i].versions.length;j++){if(res[i].versions[j].channel==='stable'){let reldate=(res[i].versions[j].current_reldate).split('/');`Chrome最新版號: ${res[i].versions[j].version}(stable) 更新日期: 20${reldate[2]}/${reldate[0]}/${reldate[1]}`;break;}}break;}}})

顯示結果:

Chrome最新版號: 96.0.4664.45(stable) 更新日期: 2021/11/15

@Eotones
Copy link
Author

Eotones commented Dec 4, 2021

[天氣] Nightbot原生的天氣指令英文轉中文

指令語法(方法一)

!weather2 Taipei
$(eval const weather=`$(weather $(query))`;let wea_arr=weather.match(/^Weather for (.*?): Conditions are (.*?) with a temperature of ([\-0-9]{1,4})F \(([\-0-9]{1,4})C\). The wind is blowing from the ([NSEW]{1,3}) at ([0-9]+)mph \(([0-9]+)km\/h\) and the current humidity is ([0-9]+)%.$/i); if(wea_arr!=null){`[${wea_arr[1]}目前天氣] 狀態:${wea_arr[2]}, 溫度:${wea_arr[4]}度C, 濕度:${wea_arr[8]}%, 風向:${wea_arr[5]}, 風速:${wea_arr[7]}km/h`}else{'error'})

顯示結果:

[Taipei目前天氣] 狀態:Fair, 溫度:16度C, 濕度:74%, 風向:E, 風速:3km/h

補充(方法二)

  • Nightbot原生天氣指令輸出的英文語句也可以用Alias丟到上面google翻譯指令來重疊使用

用法

Command:
!weather3

Message:
$(weather $(query))

Alias: (要去上方google翻譯指令找這個英翻中指令加)
!en2tw

輸出結果:

!weather3 東京
[en -> tw] @name : 東京的天氣:天氣晴朗,溫度為 52F(11C)。風從 N 以 2 英里/小時(3 公里/小時)的速度吹來,當前的濕度為 52%。

@Eotones
Copy link
Author

Eotones commented Jan 5, 2022

[日期] 使用Javascript自帶的多國語言時間格式來顯示目前時間

  • Intl.NumberFormat()

指令:

!time2
$(eval `[+8] ${new Intl.DateTimeFormat('zh-TW',{year:'numeric',month:'numeric',day:'numeric',hour:'numeric',minute:'numeric',second:'numeric',hour12:false,dayPeriod:"long",timeZone:'Asia/Taipei',weekday:"long",era:"long"}).format(new Date())} // [+9] ${new Intl.DateTimeFormat('ja',{year:'numeric',month:'numeric',day:'numeric',hour:'numeric',minute:'numeric',second:'numeric',hour12:false,dayPeriod:"long",calendar:"japanese",timeZone:'Asia/Tokyo',weekday:"long",era:"long"}).format(new Date())}`)

輸出結果:

[+8] 西元2022年1月5日 星期三 11:11:36 // [+9] 令和4年1月5日水曜日 12:11:36

參考資料

@Eotones
Copy link
Author

Eotones commented Nov 1, 2022

[遊戲] RO今日3王密碼計算(台服+8時區)

指令

nightbot後台自行新增:

!ro3boss
$(eval const _3b=(_m,_d)=>((_m+_d)*5).toString(2).padStart(8,'0');let nd=(new Date().toLocaleDateString("en-US",{timeZone:'Asia/Taipei'})).split('/');let m=nd[0]*1,d=nd[1]*1;`今日RO 3王(${m}/${d})密碼: ${_3b(m,d)}`;)

聊天室輸入指令新增:

!commands add !ro3boss $(eval const _3b=(_m,_d)=>((_m+_d)*5).toString(2).padStart(8,'0');let nd=(new Date().toLocaleDateString("en-US",{timeZone:'Asia/Taipei'})).split('/');let m=nd[0]*1,d=nd[1]*1;`今日RO 3王(${m}/${d})密碼: ${_3b(m,d)}`;)

輸出結果:

今日RO 3王(11/1)密碼: 00111100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment