1
0
Fork 0

Made the central system

This commit is contained in:
EmotionChild 2022-01-27 23:36:38 +13:00
parent e58cc7ea20
commit d7987b87ae
No known key found for this signature in database
GPG key ID: 23DC06AC32786520
19 changed files with 331 additions and 10 deletions

5
.idea/.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/

12
.idea/Ellie-v4.iml Normal file
View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

7
.idea/discord.xml Normal file
View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="PROJECT_FILES" />
<option name="description" value="" />
</component>
</project>

8
.idea/modules.xml Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Ellie-v4.iml" filepath="$PROJECT_DIR$/.idea/Ellie-v4.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View file

@ -2,12 +2,20 @@
Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.com/en/1.0.0/) except date format. a-c-f-r-o
## [4.0.6-alpha] - 16-01.2022
##[4.0.6-beta1] - 27-01-2022
### Added
- Most of the main base system
## [4.0.6-alpha] - 16-01-2022
### Added
## Added
- Added the groundwork for the database system
## [4.0.5-alpha] - 6-01-2022
### Added
- Initial bot system stuff

View file

@ -4,7 +4,6 @@ import BaseCommand from '../utils/structures/BaseCommand';
import { GuildConfiguration } from '../typeorm/entities/GuildConfiguration';
export default class DiscordClient extends Client {
private _commands = new Collection<string, BaseCommand>();
private _events = new Collection<string, BaseEvent>();
private _prefix: string = '!';
@ -23,9 +22,13 @@ export default class DiscordClient extends Client {
get prefix(): string {
return this._prefix;
}
set prefix(prefix: string) {
this._prefix = prefix;
}
get configs() {
return this._configs;
}
set configs(guildConfigs: Collection<string, GuildConfiguration>) {
this._configs = guildConfigs;
}
}

View file

@ -0,0 +1,37 @@
import { Message } from "discord.js";
import BaseCommand from "../../utils/structures/BaseCommand";
import DiscordClient from "../../client/client";
import { getRepository, Repository } from "typeorm";
import { GuildBanLog } from '../../typeorm/entities/GuildBanLog';
import { ModerationLog } from "../../typeorm/entities/ModerationLog";
export default class BanCommand extends BaseCommand {
constructor(
private readonly modLogRepository: Repository<ModerationLog> = getRepository(
ModerationLog
)
) {
super('ban', 'mod', []);
}
async run(client: DiscordClient, message: Message, args: Array<string>) {
console.log(args);
const [memberId, ...rest] = args;
const reason = rest.join(' ');
try {
// const member = await message.guild?.members.fetch(memberId)!;
// await member.ban({ reason });
const guildBan = this.modLogRepository.create({
guildId: message.guildId!,
issuedBy: message.author.id,
issuedOn: new Date(),
type: 'ban',
reason,
memberId,
});
await this.modLogRepository.save(guildBan);
} catch (err) {
console.log(err);
}
}
}

View file

@ -0,0 +1,35 @@
import { Message } from "discord.js";
import BaseCommand from "../../utils/structures/BaseCommand";
import DiscordClient from "../../client/client";
import { getRepository } from "typeorm";
import { GuildConfiguration } from "../../typeorm/entities/GuildConfiguration";
export default class ChprefixCommand extends BaseCommand {
constructor(
private readonly guildConfigRepository = getRepository(GuildConfiguration)
) {
super('chprefix', 'mod', []);
}
async run(client: DiscordClient, message: Message, args: Array<string>) {
if (!args.length) {
message.channel.send('Please provide an argument!');
return;
}
const [newPrefix] = args;
try {
const config = client.configs.get(message.guildId!);
const updatedConfig = await this.guildConfigRepository.save({
...config,
prefix: newPrefix,
});
console.log(updatedConfig);
message.channel.send('Updated prefix successfully!');
client.configs.set(message.guildId!, updatedConfig);
console.log(client.configs);
} catch (err) {
console.log(err);
message.channel.send('Something went wrong.');
}
}
}

View file

@ -0,0 +1,35 @@
import { Message } from "discord.js";
import BaseCommand from "../../utils/structures/BaseCommand";
import DiscordClient from "../../client/client";
import { GuildConfiguration } from "../../typeorm/entities/GuildConfiguration";
import { getRepository } from "typeorm";
export default class ChwelcomechannelCommand extends BaseCommand {
constructor(
private readonly guildConfigRepository = getRepository(GuildConfiguration)
) {
super('chwemcomechannel', 'mod', []);
}
async run(client: DiscordClient, message: Message, args: Array<string>) {
if (!args.length) {
message.channel.send('Please provide an argument!');
return;
}
const [newChannelId] = args;
try {
const config = client.configs.get(message.guildId!);
const updatedConfig = await this.guildConfigRepository.save({
...config,
welcomeChannelId: newChannelId,
});
console.log(updatedConfig);
message.channel.send('Updated Welcome Channel successfully!');
client.configs.set(message.guildId!, updatedConfig);
console.log(client.configs);
} catch (err) {
console.log(err);
message.channel.send('Something went wrong.');
}
}
}

View file

@ -0,0 +1,38 @@
import { Message } from "discord.js";
import BaseCommand from "../../utils/structures/BaseCommand";
import DiscordClient from "../../client/client";
import { getRepository, Repository } from "typeorm";
import { ModerationLog } from "../../typeorm/entities/ModerationLog";
export default class KickCommand extends BaseCommand {
constructor(
private readonly modLogRepository: Repository<ModerationLog> = getRepository(
ModerationLog
)
) {
super('kick', 'mod', []);
}
async run(client: DiscordClient, message: Message, args: Array<string>) {
console.log(args);
const [memberId, ...rest] = args;
const reason = rest.join(' ');
try {
// const member = await message.guild?.members.fetch(memberId)!;
// await member.kick(reason);
const date = new Date();
date.setDate(date.getDate() - 6);
const modLog = this.modLogRepository.create({
guildId: message.guildId!,
memberId,
issuedBy: message.author.id,
issuedOn: date,
reason,
type: 'kick'
});
await this.modLogRepository.save(modLog);
} catch (err) {
console.log(err);
}
}
}

View file

@ -0,0 +1,41 @@
import { Message } from 'discord.js';
import BaseCommand from "../../utils/structures/BaseCommand";
import DiscordClient from "../../client/client";
import { getRepository, Repository } from "typeorm";
import { ModerationLog } from "../../typeorm/entities/ModerationLog";
export default class TimeoutCommand extends BaseCommand {
constructor(
private readonly modLogRepository: Repository<ModerationLog> = getRepository(
ModerationLog
)
) {
super('timeout', 'mod', []);
}
async run(client: DiscordClient, message: Message, args: Array<string>) {
console.log(args);
const [memberId, timeoutStr, ...rest] = args;
const reason = rest.join(' ');
const time = parseInt(timeoutStr);
if (isNaN(time)) {
message.channel.send('Invalid Time');
return;
}
try {
const member = await message.guild?.members.fetch(memberId)!;
await member.timeout(time * 1000, reason);
const modLog = this.modLogRepository.create({
guildId: message.guildId!,
memberId,
issuedBy: message.author.id,
issuedOn: new Date(),
reason,
type: 'timeout',
});
await this.modLogRepository.save(modLog);
} catch (err) {
console.log(err);
}
}
}

View file

@ -0,0 +1,27 @@
// https://discord.js.org/#/docs/main/stable/class/Client?scrollTo=e-guildMemberAdd
import { GuildMember, TextChannel} from "discord.js";
import BaseEvent from "../utils/structures/BaseEvent";
import DiscordClient from "../client/client";
export default class GuildMemberAddEvent extends BaseEvent {
constructor() {
super('guildMemberAdd');
}
async run(client: DiscordClient, member: GuildMember) {
console.log(`Guild Member Joined`);
console.log(`Joined ${member.guild.id} ${member.guild.name}`);
const config = client.configs.get(member.guild.id);
console.log(config);
if (!config) return;
if (config.welcomeChannelId) {
const channel = member.guild.channels.cache.get(
config.welcomeChannelId
) as TextChannel;
if (!channel) console.log(`No welcome channel found`);
else channel.send(`Welcome ${member}`);
} else {
console.log('No welcome channel set.');
}
}
}

View file

@ -9,11 +9,16 @@ export default class MessageEvent extends BaseEvent {
async run(client: DiscordClient, message: Message) {
if (message.author.bot) return;
if (message.content.startsWith(client.prefix)) {
const config = client.configs.get(message.guildId!);
if (!config) {
message.channel.send('No configuration set.');
return;
}
if (message.content.startsWith(config.prefix)) {
const [cmdName, ...cmdArgs] = message.content
.slice(client.prefix.length)
.trim()
.split(/\s+/);
.slice(config.prefix.length)
.trim()
.split(/\s+/);
const command = client.commands.get(cmdName);
if (command) {
command.run(client, message, cmdArgs);

View file

@ -5,7 +5,7 @@ import DiscordClient from './client/client';
import { Collection, Intents } from 'discord.js';
import { createConnection, getRepository } from 'typeorm';
import { GuildConfiguration } from './typeorm/entities/GuildConfiguration';
import {io} from 'socket.io-client';
import { io } from 'socket.io-client';
import { entities } from './typeorm/entities';
const client = new DiscordClient({

View file

@ -0,0 +1,22 @@
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
@Entity({ name: 'guild_bans' })
export class GuildBanLog {
@PrimaryGeneratedColumn()
id: number;
@Column({ name: 'guild_id' })
guildId: string;
@Column({ name: 'banned_member_id' })
bannedMemberId: string;
@Column({ name: 'issued_by' })
issuedBy: string;
@Column()
reason?: string;
@Column({ name: 'issued_on' })
issuedOn: Date;
}

View file

@ -0,0 +1,26 @@
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
import { ModerationActionType } from "../../utils/types";
@Entity({ name: 'moderation_logs' })
export class ModerationLog {
@PrimaryGeneratedColumn()
id: number;
@Column({ name: 'guild_id' })
guildId: string;
@Column({ name: 'member_id' })
memberId: string;
@Column({ name: 'issued_by' })
issuedBy: string;
@Column()
reason?: string;
@Column({ name: 'issued_on' })
issuedOn: Date;
@Column()
type: ModerationActionType;
}

View file

@ -0,0 +1,5 @@
import { GuildBanLog } from "./GuildBanLog";
import { GuildConfiguration } from "./GuildConfiguration";
import { ModerationLog } from "./ModerationLog";
export const entities = [GuildBanLog, GuildConfiguration, ModerationLog];

1
src/utils/types.ts Normal file
View file

@ -0,0 +1 @@
export type ModerationActionType = 'ban' | 'kick' | 'timeout';