私たちは、コーディングカフェ用にこの快適な Twitch チャット モジュールを Twitch 上でライブで構築しました。
特別な感謝: Comfy.JS は @AlcaDesign によって保守されている tmi.js のおかげで可能です
Comfy.JS を使用すると、わずか数行のコードで Twitch チャンネルの Twitch チャットと超簡単に統合できます。使い方については 3 分間の簡単なビデオをご覧ください: (画像をクリックするとビデオが開きます)
これらのプロジェクトが気に入りましたか?私のオープンソース プロジェクトをサポートする最善の方法は、GitHub の Comfy スポンサーになることです。
https://github.com/sponsors/instafluff
Twitch の Comfiest コーナーにぜひ遊びに来てください!
https://twitch.tv/インスタフラッフ
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" ) ;
dist
フォルダーからcomfy.js
ダウンロードして追加するか、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()
で使用できるフラグは次のとおりです。
現在、 onCommand()
のextra
パラメータには次のフィールドが含まれています。
メッセージがコマンドの場合、 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 には、チャネル ポイント報酬を管理する機能が含まれています。これらの機能には、チャネルの Twitch OAuth パスワードの取得に使用される ClientID が必要です。
( 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、BoobieTrap、lizardqueen、TastyGamers101、MalForTheWin、SourBeers、Stay_Hydrated_Bot、codeaurora、 GermanGamer46、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、malfunct、blazeninja3、pookiepew、 xxMiabellexx、Rlcobi
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、りくりんく、rockysenpai24、DEAD_P1XL、codeaurora、EndlessMoonfall、fromtheannex、Optik_Nerve、qerwtr546、REAZNxxx、GoonPontoon、JesseSkinner、roberttables、pookiepew、Lannonbr、SoG_Cuicui、Deitypotato、シャロームハヌカブネイシモン、UpmostKek、xeiu、skatesubzero、kingswerv、K1ng440、kaisuke、kinbiko、malfunct、BoobieTrap、Kara_Kim
Comfy.JS へのチャンネル ポイント特典引き換えのための Twitch PubSub サポートの追加に参加していただいた皆様に感謝します。
Instafluff、Instafriend、informathemusic、aRandomTim、shadesofpixie、That_MS_Gamer、ToeNeeHee、httpJunkie、ryanchetty_1、calguru、chrislocality、Atanerah、rekaj3773、mosiko777、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、クロキリス、Juscekame、FuriousFur、andresurrego、MissNightcrawler、karatewump、DrillsKibo、florinpop17、Axell99Design、Ahmed_Riad_1、Keegan_GDiegen、PortaalGaming、 mjewl、cheppy4444dude、Soccerdude4444、klforthwind、penguinian、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