Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Define the bot's username used for identification in Twitch chat
TWITCH_BOT_USERNAME = "some_bot_name"

# Set the bot's OAuth token required for authenticating with the Twitch API
TWITCH_BOT_OAUTH_TOKEN = "some_bot_oauth_token"

# Specify the name of the Twitch channel that the bot will join and interact with
TWITCH_CHANNEL_NAME = "some_twitch_channel"
16 changes: 16 additions & 0 deletions assets/configs/commands.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"commands": [
{
"name": "!hello",
"response": "Hello, world!",
"cooldownInSec": 5,
"scope": "user"
},
{
"name": "!greet",
"response": "Hey there, ${sender}! Thanks for stopping by!",
"cooldownInSec": 10,
"scope": "global"
}
]
}
12 changes: 6 additions & 6 deletions src/CBWebSocket.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import WebSocket, {RawData} from "ws"
import {MessageFactory} from "./Messages/MessageFactory";
import {VotingService} from "./Voting/VotingService";
import {PrivateMessage} from "./Messages/PrivateMessage";
import WebSocket, { RawData } from "ws";
import { MessageFactory } from "./Messages/MessageFactory";
import { PrivateMessage } from "./Messages/PrivateMessage";
import { VotingService } from "./Voting/VotingService";

export class CBWebSocket {

Expand Down Expand Up @@ -30,8 +30,8 @@ export class CBWebSocket {
private registerListener() {
this.client.on("open", () => {
this.client.send(`CAP REQ :twitch.tv/commands`);
this.client.send(`PASS oauth:${process.env.TOKEN}`);
this.client.send(`NICK ${process.env.NICKNAME}`);
this.client.send(`PASS oauth:${process.env.TWITCH_BOT_OAUTH_TOKEN}`);
this.client.send(`NICK ${process.env.TWITCH_BOT_USERNAME}`);
this.client.send(`JOIN #${this.channel}`);
});

Expand Down
6 changes: 3 additions & 3 deletions src/ChatBot.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {CBWebSocket} from "./CBWebSocket";
import {ConfigStorage} from "./Config/ConfigStorage";
import { CBWebSocket } from "./CBWebSocket";
import { ConfigStorage } from "./Config/ConfigStorage";

export class ChatBot {
private socket: CBWebSocket;
Expand All @@ -11,6 +11,6 @@ export class ChatBot {
console.error(error.message);
process.exit(-1);
}
this.socket = new CBWebSocket("thecodingbuddies");
this.socket = new CBWebSocket(`${process.env.TWITCH_CHANNEL_NAME}`);
}
}
10 changes: 5 additions & 5 deletions src/Messages/CommandMessage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ConfigStorage} from "../Config/ConfigStorage";
import {PlaceHolderTransformer} from "./PlaceHolderTransformer";
import {Command} from "../Config/CommandParser";
import {PrivateMessage} from "./PrivateMessage";
import { Command } from "../Config/CommandParser";
import { ConfigStorage } from "../Config/ConfigStorage";
import { PlaceHolderTransformer } from "./PlaceHolderTransformer";
import { PrivateMessage } from "./PrivateMessage";

export class CommandMessage implements Message {
username: string;
Expand All @@ -18,7 +18,7 @@ export class CommandMessage implements Message {
this.author = this.username;
this.channel = parts[2].slice(1);
this.content = content.slice(1);
this.botName = process.env.NICKNAME;
this.botName = process.env.TWITCH_BOT_USERNAME;
} catch (e) {
throw new Error("Message incomplete");
}
Expand Down
8 changes: 4 additions & 4 deletions src/Messages/MessageFactory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {CommandMessage} from "./CommandMessage";
import {PingMessage} from "./PingMessage";
import {UnknownMessage} from "./UnknownMessage";
import {VoteMessage} from "./VoteMessage";
import { CommandMessage } from "./CommandMessage";
import { PingMessage } from "./PingMessage";
import { UnknownMessage } from "./UnknownMessage";
import { VoteMessage } from "./VoteMessage";

const voteCommandIdentifier: string[] = [":!vote", ":!vote-start"];

Expand Down
2 changes: 1 addition & 1 deletion src/Messages/PrivateMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ export class PrivateMessage {
readonly content: string;

constructor(message: string) {
this.content = `:${process.env.NICKNAME} PRIVMSG #${process.env.CHANNEL} :${message}`;
this.content = `:${process.env.TWITCH_BOT_USERNAME} PRIVMSG #${process.env.TWITCH_CHANNEL_NAME} :${message}`;
}
}
4 changes: 2 additions & 2 deletions src/Messages/VoteMessage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {VotingService} from "../Voting/VotingService";
import { VotingService } from "../Voting/VotingService";

enum VoteType {
START_DEFAULT_VOTE,
Expand Down Expand Up @@ -58,7 +58,7 @@ export class VoteMessage implements Message {
}
const chatBotResponse: string = (this.sessionName !== "default") ? `${this.sessionName} started` : "started";
return (this.isStartVoteType())
? `:${process.env.NICKNAME} PRIVMSG #${process.env.CHANNEL} :Voting ${chatBotResponse}! Options are ${this.options}`
? `:${process.env.TWITCH_BOT_USERNAME} PRIVMSG #${process.env.TWITCH_CHANNEL_NAME} :Voting ${chatBotResponse}! Options are ${this.options}`
: "";
}

Expand Down
10 changes: 5 additions & 5 deletions test/Messages/CommandMessage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {CommandMessage} from "../../src/Messages/CommandMessage";
import {Command, CommandScope} from "../../src/Config/CommandParser";
import {ConfigStorage} from "../../src/Config/ConfigStorage";
import {CommandTimeoutList} from "../../src/Config/CommandTimeoutList";
import { Command, CommandScope } from "../../src/Config/CommandParser";
import { CommandTimeoutList } from "../../src/Config/CommandTimeoutList";
import { ConfigStorage } from "../../src/Config/ConfigStorage";
import { CommandMessage } from "../../src/Messages/CommandMessage";

const testCommandTimoutInSec: number = 2;
const mockGetCommand = (): Command[] => {
Expand Down Expand Up @@ -38,7 +38,7 @@ describe('CommandMessageTest', () => {
let timeoutList: CommandTimeoutList;

beforeEach(() => {
process.env.NICKNAME = "nickname";
process.env.TWITCH_BOT_USERNAME = "nickname";
process.env.CHANNEL = "channel";
ConfigStorage.getCommands = mockGetCommand;
timeoutList = new CommandTimeoutList();
Expand Down
4 changes: 2 additions & 2 deletions test/Messages/PrivateMessage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {PrivateMessage} from "../../src/Messages/PrivateMessage";
import { PrivateMessage } from "../../src/Messages/PrivateMessage";

describe('PrivateMessage', () => {
beforeEach(() => {
process.env.NICKNAME = 'botName';
process.env.TWITCH_BOT_USERNAME = 'botName';
process.env.CHANNEL = 'ourChannel';
})

Expand Down
6 changes: 3 additions & 3 deletions test/Messages/VoteMessage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {VoteMessage} from "../../src/Messages/VoteMessage";
import {VotingService} from "../../src/Voting/VotingService";
import { VoteMessage } from "../../src/Messages/VoteMessage";
import { VotingService } from "../../src/Voting/VotingService";

describe('VoteMessage', () => {

beforeEach(() => {
process.env.NICKNAME = "nickname";
process.env.TWITCH_BOT_USERNAME = "nickname";
process.env.CHANNEL = "thecodingbuddies";
})

Expand Down