summary refs log tree commit diff
path: root/src/plugins/example-plugin/TestPlugin.ts
blob: da25c474ba620a271db8034dd2cffb68933b1bb3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import {
	Channel,
	Guild,
	Plugin,
	PluginLoadedEventArgs,
	PluginLoader,
	PluginManifest,
	PreMessageEventArgs,
	PreMessageEventResult
} from "@fosscord/util";
import { TestSettings } from "./TestSettings";

export default class TestPlugin implements Plugin {
	pluginManifest?: PluginManifest | undefined;
	settings: TestSettings = new TestSettings();
	async onPluginLoaded(env: PluginLoadedEventArgs) {
		console.log("Test plugin active!");
		if (this.pluginManifest) this.settings = PluginLoader.getPluginConfig(this.pluginManifest.id, this.settings) as TestSettings;
	}
	async onPreMessage(data: PreMessageEventArgs): Promise<PreMessageEventResult> {
		let channel = await Channel.findOne({ where: { id: data.message.channel_id } });
		let guild = await Guild.findOne({ where: { id: data.message.guild_id } });
		let block = data.message.content?.includes("UwU");

		let result = { cancel: block } as PreMessageEventResult;

		if (block) {
			console.log(
				`[TestPlugin] Blocked message in ${guild?.name}/#${channel?.name} by ${data.message.author?.username}: ${data.message.content}`
			);
			result.blockReason = "[TestPlugin] Your message contains UwU! Get bamboozled!";
		}

		return result;
	}
}