-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- DiscordBot, TwitchBot, Server into one logic - Emitter setup
- Loading branch information
Showing
59 changed files
with
504 additions
and
702 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
require('dotenv').config({path:'../.env'}); | ||
|
||
const fs = require('fs'), | ||
discord = require("discord.js"), | ||
{ Collection, Intents } = require('discord.js'), | ||
{ promisify } = require('util'); | ||
|
||
class DiscordBot { | ||
constructor() { | ||
this.guild = null; | ||
this.twitchBadge = null; | ||
|
||
this.client = new discord.Client({ | ||
intents: [ | ||
Intents.FLAGS.GUILDS, | ||
Intents.FLAGS.GUILD_MEMBERS, | ||
Intents.FLAGS.GUILD_BANS, | ||
Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS, | ||
Intents.FLAGS.GUILD_INTEGRATIONS, | ||
Intents.FLAGS.GUILD_WEBHOOKS, | ||
Intents.FLAGS.GUILD_INVITES, | ||
Intents.FLAGS.GUILD_VOICE_STATES, | ||
Intents.FLAGS.GUILD_PRESENCES, | ||
Intents.FLAGS.GUILD_MESSAGES, | ||
Intents.FLAGS.GUILD_MESSAGE_REACTIONS, | ||
Intents.FLAGS.GUILD_MESSAGE_TYPING, | ||
Intents.FLAGS.DIRECT_MESSAGES, | ||
Intents.FLAGS.DIRECT_MESSAGE_REACTIONS, | ||
Intents.FLAGS.DIRECT_MESSAGE_TYPING, | ||
] | ||
}); | ||
|
||
|
||
// commands | ||
this.client.commands = new Collection(); | ||
|
||
const commandFiles = fs.readdirSync("./discord/commands").filter((file) => file.endsWith(".js")); | ||
|
||
for (const file of commandFiles) { | ||
const command = require(`./discord/commands/${file}`); | ||
this.client.commands.set(command.data.name, command); | ||
} | ||
|
||
// events | ||
const eventFiles = fs.readdirSync('./discord/events').filter(file => file.endsWith('.js')); | ||
|
||
for (const file of eventFiles) { | ||
const event = require(`./discord/events/${file}`); | ||
if (event.once) { | ||
this.client.once(event.name, (...args) => event.execute(this.client,...args)); | ||
} else { | ||
this.client.on(event.name, (...args) => event.execute(this.client,...args)); | ||
} | ||
} | ||
} | ||
start() { | ||
this.client.login(process.env.DISCORD_TOKEN) | ||
.catch(console.error); | ||
} | ||
restart() { | ||
console.log('restarting...') | ||
this.client.destroy() | ||
.then(() => { | ||
this.start(); | ||
}); | ||
} | ||
// update stream-notification channel | ||
updateStreamNotificationChannel(channel) { | ||
|
||
} | ||
sendMessage(channelId, message) { | ||
const channel = this.guild.channels.cache.get(channelId); | ||
channel.send(message); | ||
|
||
} | ||
liveNotification(channelId, streamer) { | ||
const channel = this.guild.channels.cache.get(channelId), | ||
message = `Hey @everyone, <@${streamer.discordId}> has gone live on Twitch Watch them here: \n` | ||
+ `https://www.twitch.tv/${streamer.twitchName}`; | ||
channel.send(message); | ||
|
||
} | ||
liveEmbed(rank, streamers) { | ||
const channel = this.guild.channels.cache.get(rank.channelId); | ||
if(!rank.messageId) { | ||
const embed = generateEmbed(rank,streamers); | ||
channel.send(embed); | ||
rank.messageId = embed.id; | ||
} | ||
else { | ||
rank.messageId.edit(generateEmbed(rank,streamers)) | ||
} | ||
// check if bot sent a message before | ||
// if yes, update it | ||
// else, create a new one | ||
} | ||
// update stats channels | ||
// update featured | ||
// update levels | ||
// backup | ||
// logs | ||
} | ||
|
||
module.exports = { DiscordBot }; |
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,77 @@ | ||
require('dotenv').config({path:'../.env'}); | ||
|
||
const fs = require('fs'), | ||
tmi = require('tmi.js'), | ||
{ Collection } = require('discord.js'); | ||
|
||
class TwitchBot { | ||
constructor(channels) { | ||
console.log(channels) | ||
this.client = new tmi.Client({ | ||
options: { | ||
debug: true, | ||
messagesLogLevel: "info" | ||
}, | ||
connection: { | ||
reconnect: true, | ||
secure: true | ||
}, | ||
identity: { | ||
username: `${process.env.TWITCH_BOT_USERNAME}`, | ||
password: `oauth:${process.env.TWITCH_ACCESS_TOKEN}` | ||
}, | ||
channels | ||
}); | ||
|
||
// commands | ||
this.client.commands = new Collection(); | ||
|
||
const commandFiles = fs.readdirSync("./twitch/commands").filter((file) => file.endsWith(".js")); | ||
|
||
for (const file of commandFiles) { | ||
const command = require(`./twitch/commands/${file}`); | ||
this.client.commands.set(command.name, command); | ||
} | ||
|
||
// events | ||
const eventFiles = fs.readdirSync('./twitch/events').filter(file => file.endsWith('.js')); | ||
|
||
for (const file of eventFiles) { | ||
const event = require(`./twitch/events/${file}`); | ||
if (event.once) { | ||
this.client.once(event.name, (...args) => event.execute(this.client,...args)); | ||
} else { | ||
this.client.on(event.name, (...args) => event.execute(this.client,...args)); | ||
} | ||
} | ||
} | ||
start() { | ||
console.log('starting...') | ||
this.client.connect().catch(err => console.log(err)); | ||
} | ||
disconnect() { | ||
console.log('disconnecting...') | ||
this.client.disconnect() | ||
.then((data) => { | ||
// data returns [server, port] | ||
}).catch(err => console.log(err)); | ||
} | ||
restart(){ | ||
console.log('restarting...') | ||
this.client.disconnect().catch(err => console.log(err)); | ||
this.start(); | ||
} | ||
join(channel) { | ||
this.client.join(channel).catch(err => console.log(err)); | ||
} | ||
leave(channel) { | ||
this.client.part(channel).catch(err => console.log(err)); | ||
} | ||
host(channel, target) { | ||
this.client.host(channel, target).catch(err => console.log(err)); | ||
} | ||
// TODO: to verify a user, send a message to whisper | ||
|
||
} | ||
|
||
module.exports = { TwitchBot }; |
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.