Skip to content

Commit

Permalink
fix(*): Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
Barely-Awake committed Nov 1, 2022
1 parent 01878b0 commit d950538
Show file tree
Hide file tree
Showing 51 changed files with 1,157 additions and 782 deletions.
6 changes: 3 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

version: 2
updates:
- package-ecosystem: "npm" # See documentation for possible values
directory: "/" # Location of package manifests
- package-ecosystem: 'npm' # See documentation for possible values
directory: '/' # Location of package manifests
schedule:
interval: "daily"
interval: 'daily'
1 change: 1 addition & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ that aims to be an **open source** alternative to many discord bots.

Some features that are planned:

* Basic Moderation Commands
* Leveling
* Auto Mod
* Logging
* Reports
* Twitch & YouTube tracking
* Reaction Roles
* Suggestions
- Basic Moderation Commands
- Leveling
- Auto Mod
- Logging
- Reports
- Twitch & YouTube tracking
- Reaction Roles
- Suggestions

And that's just some features planned. Keep in mind those features are
only **planned** and none of them are implemented right now. It's going to
Expand Down
56 changes: 34 additions & 22 deletions src/bot/botData.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Collection, ColorResolvable, EmbedBuilder, SelectMenuComponentOptionData } from 'discord.js';
import {
Collection,
ColorResolvable,
EmbedBuilder,
SelectMenuComponentOptionData,
} from 'discord.js';
import { CommandClass } from '../types/discord.js';

export const botColors: ColorResolvable[] = [
'#e0006f',
'#a14b94',
'#002da4',
];
export const botColors: ColorResolvable[] = ['#e0006f', '#a14b94', '#002da4'];

export const botEmojis = {
online: '<:online:979932796162293822>',
Expand All @@ -16,40 +17,50 @@ export const botEmojis = {

export type CommandCollection = Collection<string, CommandClass>;

export type CommandCategory = 'config' | 'info' | 'moderation' | 'minecraft' | 'externalApis' | 'misc';
export type CommandCategory =
| 'config'
| 'info'
| 'moderation'
| 'minecraft'
| 'externalApis'
| 'misc';

/*
* Object Keys should be filled out following the template below
* <pre>
* exampleCategory: {
* description: 'This field will show up under the description of the category',
* label: 'This will be the user facing name of the category',
* value: 'exampleCategory', // Value should be the same as the object key
* embed: new EmbedBuilder(),
* }
* </pre>
*/
* Object Keys should be filled out following the template below
* <pre>
* exampleCategory: {
* description: 'This field will show up under the description of the category',
* label: 'This will be the user facing name of the category',
* value: 'exampleCategory', // Value should be the same as the object key
* embed: new EmbedBuilder(),
* }
* </pre>
*/
export const categoryInfo: { [index: string]: CategoryInfo } = {
config: {
description: 'Allows you to configure elements of the bot like the prefix in the current guild',
description:
'Allows you to configure elements of the bot like the prefix in the current guild',
label: 'Config',
value: 'config',
embed: new EmbedBuilder(),
},
info: {
description: 'Contain information about the bot, like performance, invite, etc...',
description:
'Contain information about the bot, like performance, invite, etc...',
label: 'Info',
value: 'info',
embed: new EmbedBuilder(),
},
moderation: {
description: 'Useful for server moderation, allows you to ban, kick, set up auto mod (soon), etc...',
description:
'Useful for server moderation, allows you to ban, kick, set up auto mod (soon), etc...',
label: 'Moderation',
value: 'moderation',
embed: new EmbedBuilder(),
},
minecraft: {
description: 'Allows you to check information on players like their skin, stats, etc...',
description:
'Allows you to check information on players like their skin, stats, etc...',
label: 'Minecraft',
value: 'minecraft',
embed: new EmbedBuilder(),
Expand All @@ -61,7 +72,8 @@ export const categoryInfo: { [index: string]: CategoryInfo } = {
embed: new EmbedBuilder(),
},
misc: {
description: 'Random useful commands that didn\'t fit well in any other category',
description:
"Random useful commands that didn't fit well in any other category",
label: 'Misc',
value: 'misc',
embed: new EmbedBuilder(),
Expand Down
6 changes: 3 additions & 3 deletions src/bot/commands/_command.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Template command
import { Message } from 'discord.js';
import { CommandClass } from '../../types/discord.js';
import { CommandCategory } from '../botData.js';
import { CommandClass } from '../../types/discord.js';
import { Message } from 'discord.js';

export default class _Example implements CommandClass {
public name: string;
Expand All @@ -15,7 +15,7 @@ export default class _Example implements CommandClass {
category: CommandCategory = 'info',
aliases: string[] | null = ['example_'], // Set to null for no aliases
description = 'Example command',
usage = '<Required Argument> [Optional Argument]',
usage = '<Required Argument> [Optional Argument]'
) {
this.name = name;
this.category = category;
Expand Down
51 changes: 21 additions & 30 deletions src/bot/commands/config/muterole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class MuteRole {
category: CommandCategory = 'config',
aliases: string[] | null = null,
description = 'Lets you set a custom mute role or makes one for you.',
usage = '<set|make> [role]',
usage = '<set|make> [role]'
) {
this.name = name;
this.category = category;
Expand All @@ -40,22 +40,20 @@ export default class MuteRole {
let muteRole: Role;
if (args[0] === 'make') {
const role = await createMuteRole(message);
if (!role)
return error('Could not create mute role.', message);
if (!role) return error('Could not create mute role.', message);

muteRole = role;
} else if (args[0] === 'set') {
const role = await resolveRole(message, args[1]);

if (!role)
return error('Please provide a role', message);
if (!role) return error('Please provide a role', message);

muteRole = role;
} else {
return error('Please provide valid arguments', message);
}

let guild = (await GuildData.find({serverId: message.guild!.id}))[0];
let guild = (await GuildData.find({ serverId: message.guild!.id }))[0];

if (guild === undefined)
guild = new GuildData({
Expand All @@ -79,40 +77,33 @@ async function createMuteRole(message: Message) {

if (muteRole === undefined) {
await error(
`I couldn't create a mute role, do I have the correct permissions?`,
message,
"I couldn't create a mute role, do I have the correct permissions?",
message
);
return null;
}

await message.guild!.channels.fetch();
if (!message.guild!.channels.cache)
return muteRole;
if (!message.guild!.channels.cache) return muteRole;

message.guild!.channels.cache.forEach((channel) => {
if (channel.isThread())
return;
if (channel.isThread()) return;

if (channel.isTextBased()) {
channel.permissionOverwrites.create(
muteRole,
{
SendMessages: false,
SendMessagesInThreads: false,
CreatePublicThreads: false,
CreatePrivateThreads: false,
AddReactions: false,
});
channel.permissionOverwrites.create(muteRole, {
SendMessages: false,
SendMessagesInThreads: false,
CreatePublicThreads: false,
CreatePrivateThreads: false,
AddReactions: false,
});
} else if (channel.isVoiceBased()) {
channel.permissionOverwrites.create(
muteRole,
{
Connect: false,
Speak: false,
Stream: false,
UseEmbeddedActivities: false,
},
);
channel.permissionOverwrites.create(muteRole, {
Connect: false,
Speak: false,
Stream: false,
UseEmbeddedActivities: false,
});
}
});

Expand Down
18 changes: 12 additions & 6 deletions src/bot/commands/config/setprefix.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Message } from 'discord.js';
import { GuildData } from '../../../mongo/guildData.js';
import { onlyInGuild, requireArgs, requirePermission } from '../../../utils/discord/commandDecorators.js';
import {
onlyInGuild,
requireArgs,
requirePermission,
} from '../../../utils/discord/commandDecorators.js';
import { CommandCategory } from '../../botData.js';

export default class SetPrefix {
Expand All @@ -15,7 +19,7 @@ export default class SetPrefix {
category: CommandCategory = 'config',
aliases: string[] | null = null,
description = 'Sets prefix in current guild',
usage = '<prefix>',
usage = '<prefix>'
) {
this.name = name;
this.category = category;
Expand All @@ -30,13 +34,15 @@ export default class SetPrefix {
async command(message: Message, args: string[]) {
const prefix = args.join(' ');

const fetchedData = await GuildData.find({serverId: message.guild!.id});
const fetchedData = await GuildData.find({ serverId: message.guild!.id });

let guildInfo;
if (fetchedData.length === 0)
guildInfo = new GuildData({serverId: message.guild!.id, prefix: prefix});
else
guildInfo = fetchedData[0];
guildInfo = new GuildData({
serverId: message.guild!.id,
prefix: prefix,
});
else guildInfo = fetchedData[0];

guildInfo.prefix = prefix;
guildInfo.save();
Expand Down
45 changes: 29 additions & 16 deletions src/bot/commands/externalApis/github.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { User } from '@saber2pr/types-github-api';
import { CommandCategory, botColors } from '../../botData.js';
import { EmbedBuilder, Message } from 'discord.js';
import { User } from '@saber2pr/types-github-api';
import { error } from '../../../utils/discord/responses.js';
import fetch from 'node-fetch';
import sharp from 'sharp';
import { requireArgs } from '../../../utils/discord/commandDecorators.js';
import { messageTimeStamp } from '../../../utils/discord/misc.js';
import { error } from '../../../utils/discord/responses.js';
import { requireArgs } from '../../../utils/discord/commandDecorators.js';
import sharp from 'sharp';
import { unixToSeconds } from '../../../utils/misc/time.js';
import { botColors, CommandCategory } from '../../botData.js';

export default class GitHub {
public name: string;
Expand All @@ -20,7 +20,7 @@ export default class GitHub {
category: CommandCategory = 'externalApis',
aliases: string[] | null = null,
description = 'Provides information on a GitHub user.',
usage = '<user>',
usage = '<user>'
) {
this.name = name;
this.category = category;
Expand All @@ -37,8 +37,7 @@ export default class GitHub {
try {
const response = await fetch(`https://api.github.com/users/${user}`);

if (!response.ok)
return error('User not found', message);
if (!response.ok) return error('User not found', message);

userData = await response.json();
} catch {
Expand All @@ -49,19 +48,29 @@ export default class GitHub {
const timeUpdated = unixToSeconds(Date.parse(userData.updated_at));

let embed = new EmbedBuilder()
.setTitle(`GitHub User \`${userData.login}\`${userData.name ? ` (${userData.name})` : ''}`)
.setTitle(
`GitHub User \`${userData.login}\`${
userData.name ? ` (${userData.name})` : ''
}`
)
.setColor(botColors[1])
.setThumbnail(userData.avatar_url)
.setDescription(userData.bio || 'Unknown')
.setURL(userData.html_url)
.addFields([
{
name: 'Created',
value: `${messageTimeStamp(timeCreated)} (${messageTimeStamp(timeCreated, 'R')})`,
value: `${messageTimeStamp(timeCreated)} (${messageTimeStamp(
timeCreated,
'R'
)})`,
},
{
name: 'Updated',
value: `${messageTimeStamp(timeUpdated)} (${messageTimeStamp(timeUpdated, 'R')})`,
value: `${messageTimeStamp(timeUpdated)} (${messageTimeStamp(
timeUpdated,
'R'
)})`,
},
{
name: 'Website',
Expand Down Expand Up @@ -91,12 +100,14 @@ export default class GitHub {

let contributionGraph;
try {
const response = await fetch(`https://ghchart.rshah.org/5865F2/${userData.login.toLocaleLowerCase()}`);
const response = await fetch(
`https://ghchart.rshah.org/5865F2/${userData.login.toLocaleLowerCase()}`
);

if (response.ok)
contributionGraph = Buffer.from(await response.arrayBuffer()); // Converts response to svg file buffer
else
contributionGraph = false;
contributionGraph = Buffer.from(await response.arrayBuffer());
// Converts response to svg file buffer
else contributionGraph = false;
} catch {
contributionGraph = false;
}
Expand All @@ -106,7 +117,9 @@ export default class GitHub {
});

// Sets the embed image to the provided attachment on the message.
embed = embed.setImage(`attachment://${userData.login.toLocaleLowerCase()}-graph.png`);
embed = embed.setImage(
`attachment://${userData.login.toLocaleLowerCase()}-graph.png`
);

message.channel.send({
embeds: [embed],
Expand Down

0 comments on commit d950538

Please sign in to comment.