Made the central system
This commit is contained in:
parent
e58cc7ea20
commit
d7987b87ae
19 changed files with 331 additions and 10 deletions
5
.idea/.gitignore
vendored
Normal file
5
.idea/.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
12
.idea/Ellie-v4.iml
Normal file
12
.idea/Ellie-v4.iml
Normal 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
7
.idea/discord.xml
Normal 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
8
.idea/modules.xml
Normal 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
6
.idea/vcs.xml
Normal 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>
|
12
CHANGELOG.md
12
CHANGELOG.md
|
@ -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
|
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
|
- Added the groundwork for the database system
|
||||||
|
|
||||||
## [4.0.5-alpha] - 6-01-2022
|
## [4.0.5-alpha] - 6-01-2022
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Initial bot system stuff
|
- Initial bot system stuff
|
|
@ -4,7 +4,6 @@ import BaseCommand from '../utils/structures/BaseCommand';
|
||||||
import { GuildConfiguration } from '../typeorm/entities/GuildConfiguration';
|
import { GuildConfiguration } from '../typeorm/entities/GuildConfiguration';
|
||||||
|
|
||||||
export default class DiscordClient extends Client {
|
export default class DiscordClient extends Client {
|
||||||
|
|
||||||
private _commands = new Collection<string, BaseCommand>();
|
private _commands = new Collection<string, BaseCommand>();
|
||||||
private _events = new Collection<string, BaseEvent>();
|
private _events = new Collection<string, BaseEvent>();
|
||||||
private _prefix: string = '!';
|
private _prefix: string = '!';
|
||||||
|
@ -23,9 +22,13 @@ export default class DiscordClient extends Client {
|
||||||
get prefix(): string {
|
get prefix(): string {
|
||||||
return this._prefix;
|
return this._prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
set prefix(prefix: string) {
|
set prefix(prefix: string) {
|
||||||
this._prefix = prefix;
|
this._prefix = prefix;
|
||||||
}
|
}
|
||||||
|
get configs() {
|
||||||
|
return this._configs;
|
||||||
|
}
|
||||||
|
set configs(guildConfigs: Collection<string, GuildConfiguration>) {
|
||||||
|
this._configs = guildConfigs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
37
src/commands/mod/BanCommand.ts
Normal file
37
src/commands/mod/BanCommand.ts
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
35
src/commands/mod/ChprefixCommand.ts
Normal file
35
src/commands/mod/ChprefixCommand.ts
Normal 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.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
35
src/commands/mod/ChwelcomechannelCommand.ts
Normal file
35
src/commands/mod/ChwelcomechannelCommand.ts
Normal 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.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
38
src/commands/mod/KickCommand.ts
Normal file
38
src/commands/mod/KickCommand.ts
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
41
src/commands/mod/TimeoutCommand.ts
Normal file
41
src/commands/mod/TimeoutCommand.ts
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,11 +9,16 @@ export default class MessageEvent extends BaseEvent {
|
||||||
|
|
||||||
async run(client: DiscordClient, message: Message) {
|
async run(client: DiscordClient, message: Message) {
|
||||||
if (message.author.bot) return;
|
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
|
const [cmdName, ...cmdArgs] = message.content
|
||||||
.slice(client.prefix.length)
|
.slice(config.prefix.length)
|
||||||
.trim()
|
.trim()
|
||||||
.split(/\s+/);
|
.split(/\s+/);
|
||||||
const command = client.commands.get(cmdName);
|
const command = client.commands.get(cmdName);
|
||||||
if (command) {
|
if (command) {
|
||||||
command.run(client, message, cmdArgs);
|
command.run(client, message, cmdArgs);
|
||||||
|
|
|
@ -5,7 +5,7 @@ import DiscordClient from './client/client';
|
||||||
import { Collection, Intents } from 'discord.js';
|
import { Collection, Intents } from 'discord.js';
|
||||||
import { createConnection, getRepository } from 'typeorm';
|
import { createConnection, getRepository } from 'typeorm';
|
||||||
import { GuildConfiguration } from './typeorm/entities/GuildConfiguration';
|
import { GuildConfiguration } from './typeorm/entities/GuildConfiguration';
|
||||||
import {io} from 'socket.io-client';
|
import { io } from 'socket.io-client';
|
||||||
import { entities } from './typeorm/entities';
|
import { entities } from './typeorm/entities';
|
||||||
|
|
||||||
const client = new DiscordClient({
|
const client = new DiscordClient({
|
||||||
|
|
22
src/typeorm/entities/GuildBanLog.ts
Normal file
22
src/typeorm/entities/GuildBanLog.ts
Normal 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;
|
||||||
|
}
|
26
src/typeorm/entities/ModerationLog.ts
Normal file
26
src/typeorm/entities/ModerationLog.ts
Normal 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;
|
||||||
|
}
|
5
src/typeorm/entities/index.ts
Normal file
5
src/typeorm/entities/index.ts
Normal 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
1
src/utils/types.ts
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export type ModerationActionType = 'ban' | 'kick' | 'timeout';
|
Reference in a new issue