Skip to content

Commit

Permalink
adding message support
Browse files Browse the repository at this point in the history
  • Loading branch information
trent-001 committed Jul 23, 2024
1 parent 6cd78d2 commit 296830d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
9 changes: 8 additions & 1 deletion commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export default {
.addRoleOption((option) =>
option.setName("mention").setDescription("Role to notify")
)
.addStringOption((option) =>
option
.setName("message")
.setDescription("Message to send")
.setRequired(false)
)
.addBooleanOption((option) =>
option
.setName("keep_vod")
Expand All @@ -48,6 +54,7 @@ export default {
const channel = inter.options.getChannel("channel");
const keep_vod = inter.options.getBoolean("keep_vod");
const mention = inter.options.getRole("mention");
const message = inter.options.getString("message");
try {
const dataLiveReq = await fetch(
process.env.API_SERVER + "/v2/live/twitch/" + username,
Expand Down Expand Up @@ -99,9 +106,9 @@ export default {
channel: channel?.id || "",
server: inter.guild?.id || "",
account: inter.user.id,
message: data.id,
keep_vod: keep_vod || false,
mention: mention?.id || null,
message: message || null,
});
} catch (error) {
console.error("Error executing add command: ", error);
Expand Down
1 change: 1 addition & 0 deletions db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ export const discordBotTwitch = pgTable("discord_bot_twitch", {
social_links: boolean("social_links").default(false).notNull(),
keep_vod: boolean("keep_vod").default(false).notNull(),
mention: text("mention"),
message: text("message"),
});
1 change: 1 addition & 0 deletions events/interactionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ discord.on(
social_links: false,
keep_vod: data.keep_vod || false,
mention: data.mention || null,
message: data.message || null,
})
.returning();
if (!dataDB) {
Expand Down
14 changes: 8 additions & 6 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ discord.on(Events.ClientReady, async () => {
console_log.colour(discord?.user?.username + " bot is ready", "green");
await registerSlashCommands();
setInterval(timeCheck, 1000);
TwitchEmbedLoop();
});
import "./events/interactionCreate";
function timeCheck() {
Expand Down Expand Up @@ -141,10 +142,10 @@ const twitchLiveEmbeds = async (item: ITwitch, index: number) => {
.setLabel("Watch Stream")
.setStyle(ButtonStyle.Link)
.setURL(`https://www.twitch.tv/${item.username.toLowerCase()}`);
let buttonLinks = new ButtonBuilder()
.setLabel("Social Links")
.setStyle(ButtonStyle.Link)
.setURL("https://doras.to/trent");
// let buttonLinks = new ButtonBuilder()
// .setLabel("Social Links")
// .setStyle(ButtonStyle.Link)
// .setURL("https://doras.to");
let row: any = new ActionRowBuilder().addComponents(buttonWatch);
if (!dataLive.live) {
buttonWatch.setLabel("Watch Vod");
Expand Down Expand Up @@ -184,7 +185,7 @@ const twitchLiveEmbeds = async (item: ITwitch, index: number) => {
return;
}
if (!channel.isTextBased()) return;
if (item.social_links) row.addComponents(buttonLinks);
// if (item.social_links) row.addComponents(buttonLinks);
let mention: any =
item.mention && discordServer.roles.cache.get(item.mention);
if (
Expand All @@ -193,7 +194,8 @@ const twitchLiveEmbeds = async (item: ITwitch, index: number) => {
) {
mention = mention.name;
} else {
mention = mention ? `<@&${item.mention}>` : "";
const message = item.message ? item.message : "";
mention = mention ? `<@&${item.mention}> ${message}` : message;
}
if (!item.message_id) {
const message = await channel.send({
Expand Down

0 comments on commit 296830d

Please sign in to comment.