เราสร้างโมดูลแชท Comfy Twitch นี้ขึ้นมาบน Twitch สำหรับ Coding Cafe!
ขอขอบคุณเป็นพิเศษ: Comfy.JS เป็นไปได้ด้วย tmi.js ที่ดูแลโดย @AlcaDesign
Comfy.JS ช่วยให้คุณสามารถรวมเข้ากับแชท Twitch สำหรับช่อง Twitch ของคุณ ได้อย่างง่ายดายเป็นพิเศษ ด้วยโค้ดเพียงไม่กี่บรรทัด นี่คือวิดีโอสั้นๆ 3 นาทีเกี่ยวกับวิธีการใช้งาน: (คลิกที่ภาพเพื่อเปิดวิดีโอ)
ชอบโครงการเหล่านี้หรือไม่? วิธีที่ดีที่สุดในการสนับสนุนโครงการโอเพ่นซอร์สของฉันคือการเป็น Comfy Sponsor บน GitHub!
https://github.com/sponsors/instafluff
มาออกไปเที่ยวกับเราที่ Comfiest Corner บน Twitch!
https://twitch.tv/instafluff
comfy.js
npm install comfy.js --save
var ComfyJS = require ( "comfy.js" ) ;
ComfyJS . onCommand = ( user , command , message , flags , extra ) => {
if ( flags . broadcaster && command === "test" ) {
console . log ( "!test was typed in chat" ) ;
}
}
ComfyJS . Init ( "MyTwitchChannel" ) ;
comfy.js
จากโฟลเดอร์ dist
หรือรวมจาก JSDelivr CDN: < script src = "comfy.min.js" > < / script >
หรือ
< script src = "https://cdn.jsdelivr.net/npm/comfy.js@latest/dist/comfy.min.js" > < / script >
< html >
< head >
< script src =" https://cdn.jsdelivr.net/npm/comfy.js@latest/dist/comfy.min.js " > </ script >
</ head >
< body >
< script type =" text/javascript " >
ComfyJS . onCommand = ( user , command , message , flags , extra ) => {
if ( flags . broadcaster && command === "test" ) {
console . log ( "!test was typed in chat" ) ;
}
}
ComfyJS . Init ( "MyTwitchChannel" ) ;
</ script >
</ body >
</ html >
ปัจจุบัน ค่าสถานะที่เป็นไปได้ใน onCommand()
และ onChat()
คือ:
ปัจจุบัน พารามิเตอร์ extra
สำหรับ onCommand()
มีฟิลด์ต่อไปนี้:
หากข้อความเป็นคำสั่ง พารามิเตอร์ extra
จะมีฟิลด์เพิ่มเติม:
ซึ่งมีข้อมูลเกี่ยวกับช่วงเวลาใน ms
นับตั้งแต่ครั้งสุดท้ายที่ผู้ใช้หรือผู้ใช้รายใดรายหนึ่งได้ใช้คำสั่งเดียวกัน ช่องนี้สามารถใช้เพื่อตั้งค่าคูลดาวน์โดยรวมหรือตัวกรองสแปมได้อย่างสะดวก ดูตัวอย่างด้านล่าง:
ComfyJS . onChat = ( user , message , flags , self , extra ) => {
if ( flags . broadcaster && command === "test" ) {
if ( extra . sinceLastCommand . any < 100 ) {
console . log (
`The last '!test' command by any user was sent less than 100 ms ago`
) ;
}
if ( extra . sinceLastCommand . user < 100 ) {
console . log (
`The last '!test' command by this specific user (as denoted by the 'user' parameter) was sent less than 100 ms ago`
) ;
}
}
}
คุณสามารถอ่านข้อความแชทได้โดยใช้ตัวจัดการ onChat()
ComfyJS . onChat = ( user , message , flags , self , extra ) => {
console . log ( user , message ) ;
}
การส่งข้อความแชทสามารถทำได้ผ่าน ComfyJS.Say( message )
แต่ต้องใช้รหัสผ่าน OAUTH เมื่อเชื่อมต่อกับแชท
dotenv
npm install dotenv --save
.env
ที่มีลักษณะดังนี้: TWITCHUSER = [ YOUR - USERNAME - HERE ]
OAUTH = [ YOUR - OAUTH - PASS HERE ] # e . g . OAUTH = oauth : kjh12bn1hsj78445234
var ComfyJS = require ( "comfy.js" ) ;
ComfyJS . onCommand = ( user , command , message , flags , extra ) => {
if ( command === "test" ) {
ComfyJS . Say ( "replying to !test" ) ;
}
}
ComfyJS . Init ( process . env . TWITCHUSER , process . env . OAUTH ) ;
คุณสามารถเข้าร่วมช่องหรือกลุ่มช่องอื่นได้โดยระบุใน Init()
ComfyJS . Init ( "MyTwitchChannel" , null , "ChannelToJoin" ) ;
ComfyJS . Init ( "MyTwitchChannel" , null , [ "ChannelA" , "ChannelB" , "ChannelC" ] ) ;
การแลกรางวัลแต้มช่องจำเป็นต้องมีขอบเขตการอนุญาต Twitch OAuth เพิ่มเติม (และ ต้องเป็น OAuth ของเจ้าของช่องด้วย !)
คุณสามารถใช้เครื่องมือนี้: https://twitchapps.com/tokengen/
ขอบเขต: channel:manage:redemptions channel:read:redemptions user:read:email chat:edit chat:read
ComfyJS . onReward = ( user , reward , cost , message , extra ) => {
console . log ( user + " redeemed " + reward + " for " + cost ) ;
}
Comfy.JS มีฟังก์ชันสำหรับจัดการ Channel Point Rewards ฟังก์ชันเหล่านี้จำเป็นต้องใช้ ClientID ที่ใช้ในการรับรหัสผ่าน Twitch OAuth สำหรับช่อง
( clientId, manageableOnly = true )
( clientId, rewardInfo )
( clientId, rewardId, rewardInfo )
( clientId, rewardId )
let channelRewards = await ComfyJS . GetChannelRewards ( clientId , true ) ;
let customReward = await ComfyJS . CreateChannelReward ( clientId , {
title : "Test Reward" ,
prompt : "Test Description" ,
cost : 100 ,
is_enabled : true ,
background_color : "#00E5CB" ,
is_user_input_required : false ,
is_max_per_stream_enabled : false ,
max_per_stream : 0 ,
is_max_per_user_per_stream_enabled : false ,
max_per_user_per_stream : 0 ,
is_global_cooldown_enabled : false ,
global_cooldown_seconds : 0 ,
should_redemptions_skip_request_queue : true
} ) ;
let updatedReward = await ComfyJS . UpdateChannelReward ( clientId , customReward . id , {
title : "Test Reward (Updated)" ,
prompt : "Updated Description" ,
cost : 200 ,
is_enabled : true ,
} ) ;
await ComfyJS . DeleteChannelReward ( clientId , customReward . id ) ;
คุณสามารถตัดการเชื่อมต่อจากเซิร์ฟเวอร์และทุกช่องได้โดยใช้ Disconnect()
ComfyJS . Disconnect ( ) ;
( user, command, message, flags, extra )
( user, message, flags, self, extra )
( user, message, flags, self, extra )
( id, extra )
( user, reward, cost, message, extra )
( user, self, extra )
( user, self, extra )
( user, viewers, autohost, extra )
( bannedUsername, extra )
( timedOutUsername, durationInSeconds, extra )
( user, viewers, extra )
( user, message, bits, flags, extra )
( user, message, subTierInfo, extra )
( user, message, streamMonths, cumulativeMonths, subTierInfo, extra )
( gifterUser, streakMonths, recipientUser, senderCount, subTierInfo, extra )
( gifterUser, numbOfSubs, senderCount, subTierInfo, extra )
( user, sender, extra )
( address, port, isFirstConnect )
( reconnectCount )
( error )
ขอขอบคุณผู้เข้าร่วมโครงการนี้ทุกคน!
Instafluff, Instafriend, Neo_TA, ChatTranslator, fydo, That_MS_Gamer, MrRayKoma, Amarogine, HunWalk, simrose4u, sparky_pugwash, soggycoffee, blackdawn1980, BooobieTrap, Lizardqueen, DeliciousGamers101, MalForTheWin, SourBeers, Stay_Hydrated_Bot, codeaurora, DutchGamer46, TheHungerService, BungalowGlow, koralina_211, TominationTime, itsDeke, fd_god92, SushiDay, FlyToto_, Docpinecone, katori15, ScrtSolstice, QeraiX, superravemonster, Jwh1o1, Deitypotato, Stobie, Chlapicek99, tehWokes, SuperChihuahua, FranC312, FuriousFur, Moopaloo, CreativeBuilds, donaldwm, Zorchenhimer, Grognardian, ravavyr, Chibigirl24, DR4G0N_S4MUR41, PokemoHero, rekaj3773, cunavrito, TheGeekGeneration, DevMerlin, julieee22, ทำงานผิดปกติ, blazeninja3, pookiepew, xxMiabellexx, Rlchibi
ขอบคุณทุกคนที่ช่วยเปลี่ยน Comfy.JS ให้เป็นโมดูลเบราว์เซอร์!
Instafluff, Instafriend, ChatTranslator, Gilokk0, qbotv3, That_MS_Gamer, KitAnnLIVE, simrose4u, MacabreMan2, LuRiMer313, sparky_pugwash, AbbyFabby, sethorizer, julieee22, Numb3rY, Jwh1o1, baileydale, kevkab, Stay_Hydrated_Bot, DrJavaSaurus, การทดสอบความเครียด, BungalowGlow, Dr_Zero, NiteCrawla, fd_god92, DrEriksen, codeheir, Talk2meGooseman, sneelps, cottonsmiles, DutchGamer46, LilyHazel, Kyoslilmonster, guthron, DragosNox, sciondragons, HonestDanGames, Xynal, MerlinLeWizard, FablesGames, BrainoidGames, donaldwm, Gharrotey, RIKACHET, HeyOhKei, DevMerlin, CrimsonKnightZero, ellie_pop, ItsNaomiArt, SomaPills, TheSabbyLife, bktdakid31, IsaisChannel, thegooseofwild, itsDeke, bubblesandunicorns, jellydance, MalForTheWin, Chibigirl24, Pearcington, RikuRinku, rockysenpai24, DEAD_P1XL, codeaurora, EndlessMoonfall, fromtheannex, Optik_Nerve, qerwtr546, REAZNxxx, GoonPontoon, JesseSkinner, roberttables, pookiepew, Lannonbr, SoG_Cuicui, Deitypotato, shalomhanukkahbneishimon, UpmostKek, xeiu, Skatesubzero, kingswerv, K1ng440, kaisuke, kinbiko, ทำงานผิดปกติ, BooobieTrap, Kara_Kim
ขอขอบคุณทุกคนที่เข้าร่วมในการเพิ่มการรองรับ Twitch PubSub สำหรับการแลกรางวัล Channel Point ไปยัง Comfy.JS!
Instafluff, Instafriend, informathemusic, aRandomTim, shadeofpixie, That_MS_Gamer, ToeNeeHee, httpJunkie, ryanchetty_1, calguru, chrislocality, Atanerah, rekaj3773, moshiko777, fizhes, AnnaCodes, Smokestormx, TheGeekGeneration, SavenaV, KotaKlan, rosebutterfly24, Simpathey, Spationaute, DjDesidera, JupiterZky, judybelle1, Shaezonai, Shineslove, airsickmammal, walaber, jellydance, LilyHazel, PainArtist, Nickloop_TTV, VerbatimStudios, silversurfer1989, BellaTriXrbsa, Holloway87, Asherroth86, Tiwesday, not_your_point, JenDevelops, tenaciousw, Cuicui_off, stevis5, aranhawaii, DevMerlin, wabes1, jeckle, opti_21, sparky_pugwash, tommunist_64, DutchGamer46, DoctorArgus, simrose4u, DreamGardenPanda, onelineofme, stuyksoft, Simployed, JustinZedly, Rhedone, DrMikachu, Gurkenkater, MrDemonWolf, saltipretzelz, MerlinLeWizard, Kurokirisu, Juscekame, FuriousFur, andresurrego, MissNightcrawler, karatewump, DrillsKibo, florinpop17, Axell99Design, Ahmed_Riad_1, Keegan_Gdiegen, PortaalGaming, mjewl, cheppy4444dude, Soccerdude4444, klforthwind, นกเพนกวิน, 10TenArt, Atndesign, DNIStream, LoveSudoNimh, prosto_artem27, lucasnramos, A_Ninja_For_Jesus_Bruh, RedChrisMS, Lineyatronic, Totte292, A_Gold_Fish, ShiDotMoe, tbdgamer, MatthewDGroves, dota2attitude, Mistersyntax, SekaCakes, llamakid29, CryptoCoyote, MurdocTurner, JeanValjean80, walpolea, Jessi8712, butschibuuuu, Cmiley6, TheFlamingWings, hehe24h, cryogen_sw, DrJavaSaurus, rota22_, julieee22, bronick16, ScrtSolstice, ghostlupo86, wake_the_beast, williamcameron2, GizmoPugLife, OG24com