Skip to content

Commit

Permalink
format and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lajbel committed Dec 15, 2021
1 parent 325b219 commit de4d183
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 47 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"deno.enable": true,
"deno.lint": true,
"deno.unstable": true
"deno.unstable": true,
"deno.config": "./deno.json",
"editor.formatOnSave": true,
"editor.defaultFormatter": "denoland.vscode-deno"
}
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"options": {
"useTabs": true,
"lineWidth": 160,
"lineWidth": 80,
"indentWidth": 4,
"singleQuote": false,
"proseWrap": "preserve"
Expand Down
30 changes: 20 additions & 10 deletions src/buttons/announcements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,29 @@ export default () => {

if (!interaction.member?.roles.includes(role)) {
addRole(bot, guildId, member, role).then(() => {
sendInteractionResponse(bot, interaction.id, interaction.token, {
private: true,
type: InteractionResponseTypes.ChannelMessageWithSource,
data: { content: "Announcements role added" },
});
sendInteractionResponse(
bot,
interaction.id,
interaction.token,
{
private: true,
type: InteractionResponseTypes.ChannelMessageWithSource,
data: { content: "Announcements role added" },
},
);
});
} else {
removeRole(bot, guildId, member, role).then(() => {
sendInteractionResponse(bot, interaction.id, interaction.token, {
private: true,
type: InteractionResponseTypes.ChannelMessageWithSource,
data: { content: "Announcements role removed" },
});
sendInteractionResponse(
bot,
interaction.id,
interaction.token,
{
private: true,
type: InteractionResponseTypes.ChannelMessageWithSource,
data: { content: "Announcements role removed" },
},
);
});
}
},
Expand Down
17 changes: 12 additions & 5 deletions src/commands/tip.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { sendInteractionResponse, Bot, DiscordenoInteraction, Embed, InteractionResponseTypes, } from "../deps/discordeno.ts";
import {
Bot,
DiscordenoInteraction,
Embed,
InteractionResponseTypes,
sendInteractionResponse,
} from "../deps/discordeno.ts";

export default () => {
return {
Expand All @@ -8,6 +14,7 @@ export default () => {
exe: (bot: Bot, interaction: DiscordenoInteraction) => {
const tips = [
{ t: "npm i kaboom@next", img: null },
{ t: "kaboom({\nburp: true})", img: null },
];

const tip = tips[Math.floor(Math.random() * tips.length)];
Expand All @@ -18,12 +25,12 @@ export default () => {
description: tip.t,
};

if(tip.img) embed.image = { url: tip.img };
if (tip.img) embed.image = { url: tip.img };

sendInteractionResponse(bot, interaction.id, interaction.token, {
type: InteractionResponseTypes.ChannelMessageWithSource,
data: { embeds: [ embed ] },
data: { embeds: [embed] },
});
},
};
}
};
28 changes: 14 additions & 14 deletions src/deps/discordeno.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
export {
ActivityTypes,
addRole,
ApplicationCommandOptionTypes,
ApplicationCommandTypes,
ButtonStyles,
channelOverwriteHasPermission,
createApplicationCommand,
createBot,
deleteMessage,
editBotStatus,
getMember,
getUser,
InteractionResponseTypes,
MessageComponentTypes,
OverwriteTypes,
removeRole,
sendInteractionResponse,
sendMessage,
startBot,
ActivityTypes,
ApplicationCommandOptionTypes,
ApplicationCommandTypes,
ButtonStyles,
InteractionResponseTypes,
MessageComponentTypes,
OverwriteTypes,
} from "https://deno.land/x/discordeno@13.0.0-rc11/mod.ts";

export type {
Bot,
CreateGlobalApplicationCommand,
DiscordenoInteraction,
DiscordenoMember,
DiscordenoMessage,
export type {
Bot,
CreateGlobalApplicationCommand,
DiscordenoInteraction,
DiscordenoMember,
DiscordenoMessage,
Embed,
GuildMember
GuildMember,
} from "https://deno.land/x/discordeno@13.0.0-rc11/mod.ts";
5 changes: 4 additions & 1 deletion src/events/interactionCreate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { buttonsActions, commands } from "../mod.ts";
import { Bot, DiscordenoInteraction } from "../deps/discordeno.ts";

export function interactionCreate(bot: Bot, interaction: DiscordenoInteraction) {
export function interactionCreate(
bot: Bot,
interaction: DiscordenoInteraction,
) {
// command only in guild
if (!interaction.guildId) return;

Expand Down
19 changes: 16 additions & 3 deletions src/events/messageCreate.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import { Bot, deleteMessage, DiscordenoMessage, sendMessage } from "../deps/discordeno.ts";
import {
Bot,
deleteMessage,
DiscordenoMessage,
sendMessage,
} from "../deps/discordeno.ts";

export function messageCreate(bot: Bot, message: DiscordenoMessage) {
// anti-invites for users lol
if (message.content.match(/(https:\/\/)?((discord|discordapp).((gg\/\w+)|(com\/(invite\/\w+))))/g)) {
sendMessage(bot, message.channelId, "No send invites!!! help <@632319035102462004>");
if (
message.content.match(
/(https:\/\/)?((discord|discordapp).((gg\/\w+)|(com\/(invite\/\w+))))/g,
)
) {
sendMessage(
bot,
message.channelId,
"No send invites!!! help <@632319035102462004>",
);
deleteMessage(bot, message.channelId, message.id);
}
}
15 changes: 12 additions & 3 deletions src/events/ready.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { ActivityTypes, Bot, editBotStatus, getUser } from "../deps/discordeno.ts";
import {
ActivityTypes,
Bot,
editBotStatus,
getUser,
} from "../deps/discordeno.ts";

export async function ready(bot: Bot) {
const botUser = await getUser(bot, bot.id);

console.log(`Mark is online in ${botUser.username}#${botUser.discriminator}!`);
console.log(
`Mark is online in ${botUser.username}#${botUser.discriminator}!`,
);

const funnyStatus = [
"Bean...",
Expand All @@ -21,7 +28,9 @@ export async function ready(bot: Bot) {
editBotStatus(bot, {
activities: [
{
name: funnyStatus[Math.floor(Math.random() * funnyStatus.length)],
name: funnyStatus[
Math.floor(Math.random() * funnyStatus.length)
],
type: ActivityTypes.Watching,
createdAt: 0,
buttons: [
Expand Down
18 changes: 10 additions & 8 deletions src/mod.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import { ApplicationCommandTypes, Bot, createApplicationCommand, createBot, startBot } from "./deps/discordeno.ts";
import {
ApplicationCommandTypes,
Bot,
createApplicationCommand,
createBot,
startBot,
} from "./deps/discordeno.ts";

import { config, DotenvConfig } from "./deps/dotenv.ts";

import { readDir } from "./util/readDir.ts";

import { interactionCreate } from "./events/interactionCreate.ts";
import { messageCreate } from "./events/messageCreate.ts";
import { messageDelete } from "./events/messageDelete.ts";
import { ready } from "./events/ready.ts";

const env: DotenvConfig = config();

let token = env.TOKEN;
let id = env.ID;

if (!token) token = Deno.env.get("TOKEN")!;
if (!id) id = Deno.env.get("ID")!;
const token = env.TOKEN ? env.TOKEN : Deno.env.get("TOKEN")!;
const id = env.ID ? env.ID : Deno.env.get("ID")!;

// bot setup
const bot: Bot = createBot({
Expand All @@ -25,7 +28,6 @@ const bot: Bot = createBot({
events: {
interactionCreate,
messageCreate,
messageDelete,
ready,
},
});
Expand Down
5 changes: 4 additions & 1 deletion src/util/readDir.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export async function readDir(dir: string, func: (file: Deno.DirEntry) => void) {
export async function readDir(
dir: string,
func: (file: Deno.DirEntry) => void,
) {
for await (const file of Deno.readDir(dir)) {
if (file.name.endsWith(".ts")) {
func(file);
Expand Down

0 comments on commit de4d183

Please sign in to comment.