-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
92c1cee
commit bb07b99
Showing
9 changed files
with
158 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ node_modules | |
dist | ||
dist-ssr | ||
*.local | ||
.env | ||
*.token.json | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/wolf.png" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Royal Madness</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<div id="game"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
<script type="module" src="/src/render/main.ts"></script> | ||
</body> | ||
<head> | ||
<meta charset="UTF-8"/> | ||
<link rel="icon" type="image/svg+xml" href="/wolf.png"/> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> | ||
<title>Royal Madness: Twitch Chat Game</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<div id="game"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
<script type="module" src="/src/render/main.ts"></script> | ||
</body> | ||
</html> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,30 @@ | ||
{ | ||
"name": "royal-madness-client", | ||
"name": "royal-madness-twitch-game", | ||
"version": "0.0.1", | ||
"description": "Royal Madness game client", | ||
"description": "Royal Madness: Twitch Chat Game", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc && vite build", | ||
"preview": "vite preview", | ||
"lint": "npx @biomejs/biome check --apply ./src" | ||
"lint": "npx @biomejs/biome check --apply ./src", | ||
"server": "node --env-file=.env server/main.js" | ||
}, | ||
"keywords": [ | ||
"game", | ||
"online" | ||
], | ||
"type": "module", | ||
"keywords": ["game", "online", "twitch"], | ||
"author": "Nick Kosarev <[email protected]>", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/hmbanan666/royal-madness-client.git" | ||
"url": "git+https://github.com/hmbanan666/royal-madness-twitch-game.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/hmbanan666/royal-madness-client/issues" | ||
"url": "https://github.com/hmbanan666/royal-madness-twitch-game/issues" | ||
}, | ||
"homepage": "https://github.com/hmbanan666/royal-madness-client#readme", | ||
"type": "module", | ||
"homepage": "https://github.com/hmbanan666/royal-madness-twitch-game#readme", | ||
"dependencies": { | ||
"@twurple/auth": "7.1.0", | ||
"@twurple/chat": "7.1.0", | ||
"@twurple/easy-bot": "7.1.0", | ||
"pixi.js": "8.0.2", | ||
"react": "18.2.0", | ||
"react-dom": "18.2.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { promises as fs } from "node:fs"; | ||
import { RefreshingAuthProvider } from "@twurple/auth"; | ||
import { Bot, createBotCommand } from "@twurple/easy-bot"; | ||
|
||
const channel = process.env.TWITCH_CHANNEL_NAME; | ||
const userId = process.env.TWITCH_CHANNEL_ID; | ||
|
||
const clientId = process.env.TWITCH_CLIENT_ID; | ||
const clientSecret = process.env.TWITCH_SECRET_ID; | ||
|
||
const tokenFilePath = `./server/${userId}.token.json`; | ||
|
||
const tokenData = JSON.parse(await fs.readFile(tokenFilePath, "utf-8")); | ||
|
||
const authProvider = new RefreshingAuthProvider({ | ||
clientId, | ||
clientSecret, | ||
}); | ||
|
||
authProvider.onRefresh( | ||
async (userId, newTokenData) => | ||
await fs.writeFile( | ||
tokenFilePath, | ||
JSON.stringify(newTokenData, null, 4), | ||
"utf-8", | ||
), | ||
); | ||
|
||
await authProvider.addUserForToken(tokenData, ["chat"]); | ||
|
||
const bot = new Bot({ | ||
authProvider, | ||
channels: [channel], | ||
commands: [ | ||
createBotCommand("рубить", (params, { userId, userName, reply }) => { | ||
console.log(userId, userName, params); | ||
|
||
void reply(`${userName}, ты рубишь дерево! 30 шт/минуту`); | ||
}), | ||
createBotCommand("slap", (params, { userName, say }) => { | ||
void say( | ||
`${userName} slaps ${params.join(" ")} around a bit with a large trout`, | ||
); | ||
}), | ||
], | ||
}); | ||
|
||
bot.onSub(({ broadcasterName, userName }) => { | ||
void bot.say( | ||
broadcasterName, | ||
`Thanks to @${userName} for subscribing to the channel!`, | ||
); | ||
}); | ||
bot.onResub(({ broadcasterName, userName, months }) => { | ||
void bot.say( | ||
broadcasterName, | ||
`Thanks to @${userName} for subscribing to the channel for a total of ${months} months!`, | ||
); | ||
}); | ||
bot.onSubGift(({ broadcasterName, gifterName, userName }) => { | ||
void bot.say( | ||
broadcasterName, | ||
`Thanks to @${gifterName} for gifting a subscription to @${userName}!`, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters