Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hmbanan666 committed May 8, 2024
1 parent 8ee80a5 commit 8d8df24
Show file tree
Hide file tree
Showing 113 changed files with 3,557 additions and 4,538 deletions.
90 changes: 45 additions & 45 deletions apps/api/src/bot/bot.controller.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
import { RefreshingAuthProvider } from "@twurple/auth";
import { Bot } from "@twurple/easy-bot";
import { PubSubClient } from "@twurple/pubsub";
import type { Game } from "../game/game";
import { BotService } from "./bot.service";
import { RefreshingAuthProvider } from "@twurple/auth"
import { Bot } from "@twurple/easy-bot"
import { PubSubClient } from "@twurple/pubsub"
import type { Game } from "../game/game"
import { BotService } from "./bot.service"

export class BotController {
private readonly channel = process.env.TWITCH_CHANNEL_NAME as string;
private readonly userId = process.env.TWITCH_CHANNEL_ID as string;
private readonly clientId = process.env.TWITCH_CLIENT_ID as string;
private readonly clientSecret = process.env.TWITCH_SECRET_ID as string;
private readonly channel = process.env.TWITCH_CHANNEL_NAME as string
private readonly userId = process.env.TWITCH_CHANNEL_ID as string
private readonly clientId = process.env.TWITCH_CLIENT_ID as string
private readonly clientSecret = process.env.TWITCH_SECRET_ID as string

private readonly service: BotService;
private readonly service: BotService

constructor(game: Game) {
this.service = new BotService(game);
this.service = new BotService(game)
}

private async prepareAuthProvider() {
const tokenFile = Bun.file(`./apps/api/tmp/${this.userId}.token.json`);
const tokenData = await tokenFile.json();
const tokenFile = Bun.file(`./apps/api/tmp/${this.userId}.token.json`)
const tokenData = await tokenFile.json()

const authProvider = new RefreshingAuthProvider({
clientId: this.clientId,
clientSecret: this.clientSecret,
});
})

authProvider.onRefresh(async (_, newTokenData) => {
const data = JSON.stringify(newTokenData, null, 4);
await Bun.write(tokenFile, data);
});
const data = JSON.stringify(newTokenData, null, 4)
await Bun.write(tokenFile, data)
})

await authProvider.addUserForToken(tokenData, ["chat", "channel"]);
await authProvider.addUserForToken(tokenData, ["chat", "channel"])

return authProvider;
return authProvider
}

prepareBotCommands() {
Expand All @@ -50,21 +50,21 @@ export class BotController {
this.service.commandBuy(),
this.service.commandHelp(),
this.service.commandDonate(),
];
]
}

public async serve() {
const authProvider = await this.prepareAuthProvider();
const authProvider = await this.prepareAuthProvider()

const pubSubClient = new PubSubClient({ authProvider });
const pubSubClient = new PubSubClient({ authProvider })

pubSubClient.onRedemption(this.userId, ({ userId, userName, rewardId }) => {
this.service.reactOnChannelRewardRedemption({
userId,
userName,
rewardId,
});
});
})
})

const bot = new Bot({
authProvider,
Expand All @@ -73,50 +73,50 @@ export class BotController {
chatClientOptions: {
requestMembershipEvents: true,
},
});
})

bot.onRaid(({ broadcasterName, userName, userId, viewerCount }) => {
void bot.say(broadcasterName, `@${userName} устроил(а) рейд! Готовимся!`);
void this.service.reactOnRaid({ userName, userId, viewerCount });
});
void bot.say(broadcasterName, `@${userName} устроил(а) рейд! Готовимся!`)
void this.service.reactOnRaid({ userName, userId, viewerCount })
})
bot.onRaidCancel((event) => {
console.log("raid canceled!", event);
});
console.log("raid canceled!", event)
})

bot.onMessage(({ userId, isAction, text }) => {
console.log("message", userId, isAction, text);
});
console.log("message", userId, isAction, text)
})

bot.onAction(({ userId, userName, isAction, text }) => {
console.log("action!", userId, userName, isAction, text);
});
console.log("action!", userId, userName, isAction, text)
})

bot.onJoin(({ userName }) => {
console.log(new Date().toLocaleTimeString(), "joined!", userName);
});
console.log(new Date().toLocaleTimeString(), "joined!", userName)
})
bot.onLeave(({ userName }) => {
console.log("left!", userName);
});
console.log("left!", userName)
})

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}!`,
);
});
)
})

return bot;
return bot
}
}
84 changes: 42 additions & 42 deletions apps/api/src/bot/bot.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { createBotCommand } from "@twurple/easy-bot";
import type { IGameSceneAction } from "../../../../packages/api-sdk/src";
import { TWITCH_CHANNEL_REWARDS } from "../config";
import type { Game } from "../game/game";
import { createBotCommand } from "@twurple/easy-bot"
import type { IGameSceneAction } from "../../../../packages/api-sdk/src"
import { TWITCH_CHANNEL_REWARDS } from "../config"
import type { Game } from "../game/game"

export class BotService {
public game: Game;
public game: Game

constructor(game: Game) {
this.game = game;
this.game = game
}

private buildCommand(commandName: string, action: IGameSceneAction) {
Expand All @@ -19,103 +19,103 @@ export class BotService {
userId,
userName,
params,
});
})
if (result.message) {
void reply(result.message);
void reply(result.message)
}
},
);
)
}

public commandStartChangingScene() {
return this.buildCommand("вернуться", "START_CHANGING_SCENE");
return this.buildCommand("вернуться", "START_CHANGING_SCENE")
}

public commandStartGroupBuild() {
return this.buildCommand("собрать", "START_GROUP_BUILD");
return this.buildCommand("собрать", "START_GROUP_BUILD")
}

public commandJoinGroup() {
return this.buildCommand("го", "JOIN_GROUP");
return this.buildCommand("го", "JOIN_GROUP")
}

public commandDisbandGroup() {
return this.buildCommand("расформировать", "DISBAND_GROUP");
return this.buildCommand("расформировать", "DISBAND_GROUP")
}

public commandStartCreatingNewAdventure() {
return this.buildCommand("путешествовать", "START_CREATING_NEW_ADVENTURE");
return this.buildCommand("путешествовать", "START_CREATING_NEW_ADVENTURE")
}

public commandRefuel() {
return this.buildCommand("заправить", "REFUEL");
return this.buildCommand("заправить", "REFUEL")
}

public commandChop() {
return this.buildCommand("рубить", "CHOP");
return this.buildCommand("рубить", "CHOP")
}

public commandMine() {
return this.buildCommand("добыть", "MINE");
return this.buildCommand("добыть", "MINE")
}

public commandGift() {
return this.buildCommand("подарить", "GIFT");
return this.buildCommand("подарить", "GIFT")
}

public commandSell() {
return this.buildCommand("продать", "SELL");
return this.buildCommand("продать", "SELL")
}

public commandBuy() {
return this.buildCommand("купить", "BUY");
return this.buildCommand("купить", "BUY")
}

public commandHelp() {
return this.buildCommand("помощь", "HELP");
return this.buildCommand("помощь", "HELP")
}

public commandDonate() {
return this.buildCommand("донат", "DONATE");
return this.buildCommand("донат", "DONATE")
}

public async reactOnRaid({
userName,
userId,
viewerCount,
}: {
userName: string;
userId: string;
viewerCount: number;
userName,
userId,
viewerCount,
}: {
userName: string
userId: string
viewerCount: number
}) {
return this.game.handleChatCommand({
action: "START_RAID",
userId,
userName,
viewerCount,
});
})
}

public async reactOnChannelRewardRedemption({
userId,
userName,
rewardId,
}: {
userId: string;
userName: string;
rewardId: string;
userId,
userName,
rewardId,
}: {
userId: string
userName: string
rewardId: string
}) {
console.log("reactOnChannelRewardRedemption", userId, userName, rewardId);
console.log("reactOnChannelRewardRedemption", userId, userName, rewardId)
const player = await this.game.repository.findOrCreatePlayer(
userId,
userName,
);
)
if (rewardId === TWITCH_CHANNEL_REWARDS.add150ViewerPointsId) {
await this.game.repository.addPlayerViewerPoints(player.id, 150);
return;
await this.game.repository.addPlayerViewerPoints(player.id, 150)
return
}
if (rewardId === TWITCH_CHANNEL_REWARDS.villainStealFuelId) {
await this.game.scene.stealFuelAction(player.id);
await this.game.scene.stealFuelAction(player.id)
return
}
}
Expand Down
30 changes: 15 additions & 15 deletions apps/api/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
export const SERVER_TICK_MS = 25;
export const SERVER_TICK_MS = 25

export const MIN_X = 20;
export const MAX_X = 2520;
export const MIN_X = 20
export const MAX_X = 2520

export const MIN_Y = 120;
export const MAX_Y = 1190;
export const MIN_Y = 120
export const MAX_Y = 1190

export const RAIDER_CAMP_MIN_X = 3000;
export const RAIDER_CAMP_MAX_X = 3500;
export const RAIDER_CAMP_MIN_Y = 120;
export const RAIDER_CAMP_MAX_Y = 1190;
export const RAIDER_CAMP_MIN_X = 3000
export const RAIDER_CAMP_MAX_X = 3500
export const RAIDER_CAMP_MIN_Y = 120
export const RAIDER_CAMP_MAX_Y = 1190

export const DONATE_URL = "https://www.donationalerts.com/r/hmbanan666";
export const DISCORD_SERVER_INVITE_URL = "https://discord.gg/B6etUajrGZ";
export const DONATE_URL = "https://www.donationalerts.com/r/hmbanan666"
export const DISCORD_SERVER_INVITE_URL = "https://discord.gg/B6etUajrGZ"

export const TWITCH_CHANNEL_REWARDS = {
"add150ViewerPointsId": "d8237822-c943-434f-9d7e-87a9f549f4c4",
"villainStealFuelId": "d5956de4-54ff-49e4-afbe-ee4e62718eee"
};
add150ViewerPointsId: "d8237822-c943-434f-9d7e-87a9f549f4c4",
villainStealFuelId: "d5956de4-54ff-49e4-afbe-ee4e62718eee",
}

export const ADMIN_PLAYER_ID = "svhjz9p5467wne9ybasf1bwy";
export const ADMIN_PLAYER_ID = "svhjz9p5467wne9ybasf1bwy"
4 changes: 2 additions & 2 deletions apps/api/src/db/db.client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { PrismaClient } from "@prisma/client";
import { PrismaClient } from "@prisma/client"

export const db = new PrismaClient();
export const db = new PrismaClient()
Loading

0 comments on commit 8d8df24

Please sign in to comment.