-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
249 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,68 @@ | ||
<p align="center"><a href="https://nodei.co/npm/discord-anti-spam/"><img src="https://nodei.co/npm/discord-anti-spam.png"></a></p> | ||
|
||
# discord-anti-spam.js | ||
|
||
A simple module with quick setup and different options to implement anti-spam features in your bot. | ||
|
||
## Installation | ||
|
||
To install this module type the following command in your console: | ||
|
||
``` | ||
npm i discord-anti-spam | ||
``` | ||
|
||
## Support Server | ||
|
||
Join our [Support Server](https://discord.gg/KQgDfGr) where we help you with issues regarding the module. | ||
|
||
## Bug Reports | ||
If you have any bugs or trouble setting the module up, feel free to open an issue on [Github](https://github.com/Michael-J-Scofield/discord-anti-spam) | ||
|
||
If you have any bugs or trouble setting the module up, feel free to open an issue on [Github](https://github.com/Michael-J-Scofield/discord-anti-spam) | ||
|
||
## Example | ||
|
||
Example of a basic bot handling spam messages using this module. | ||
|
||
```js | ||
const Discord = require("discord.js"); | ||
const Discord = require('discord.js'); | ||
const client = new Discord.Client(); | ||
const DiscordAntiSpam = require("discord-anti-spam"); | ||
const DiscordAntiSpam = require('discord-anti-spam'); | ||
const AntiSpam = new DiscordAntiSpam({ | ||
warnThreshold: 3, // Amount of messages sent in a row that will cause a warning. | ||
banThreshold: 7, // Amount of messages sent in a row that will cause a ban | ||
maxInterval: 2000, // Amount of time (in ms) in which messages are cosidered spam. | ||
warnMessage: "{@user}, Please stop spamming.", // Message will be sent in chat upon warning. | ||
banMessage: "**{user_tag}** has been banned for spamming.", // Message will be sent in chat upon banning. | ||
maxDuplicatesWarning: 7, // Amount of same messages sent that will be considered as duplicates that will cause a warning. | ||
maxDuplicatesBan: 15, // Amount of same messages sent that will be considered as duplicates that will cause a ban. | ||
deleteMessagesAfterBanForPastDays: 1, // Amount of days in which old messages will be deleted. (1-7) | ||
exemptPermissions: ["MANAGE_MESSAGES", "ADMINISTRATOR", "MANAGE_GUILD", "BAN_MEMBERS"], // Bypass users with at least one of these permissions | ||
ignoreBots: true, // Ignore bot messages | ||
verbose: false, // Extended Logs from module | ||
ignoredUsers: [], // Array of string user IDs that are ignored | ||
ignoredRoles: [], // Array of string role IDs or role name that are ignored | ||
ignoredGuilds: [], // Array of string Guild IDs that are ignored | ||
ignoredChannels: [] // Array of string channels IDs that are ignored | ||
warnThreshold: 3, // Amount of messages sent in a row that will cause a warning. | ||
banThreshold: 7, // Amount of messages sent in a row that will cause a ban. | ||
maxInterval: 2000, // Amount of time (in milliseconds) in which messages are considered spam. | ||
warnMessage: '{@user}, Please stop spamming.', // Message that will be sent in chat upon warning a user. | ||
banMessage: '**{user_tag}** has been banned for spamming.', // Message that will be sent in chat upon banning a user. | ||
maxDuplicatesWarning: 7, // Amount of duplicate messages that trigger a warning. | ||
maxDuplicatesBan: 15, // Amount of duplicate messages that trigger a ban. | ||
deleteMessagesAfterBanForPastDays: 1, // Days of messages that get deleted upon banning a user. | ||
exemptPermissions: [ | ||
'MANAGE_MESSAGES', | ||
'ADMINISTRATOR', | ||
'MANAGE_GUILD', | ||
'BAN_MEMBERS' | ||
], // Bypass users with any of these permissions. | ||
ignoreBots: true, // Ignore bot messages. | ||
verbose: false, // Extended Logs from module. | ||
ignoredUsers: [], // Array of User IDs that get ignored. | ||
ignoredRoles: [], // Array of Role IDs or names that are ignored. | ||
ignoredGuilds: [], // Array of Guild IDs that are ignored. | ||
ignoredChannels: [] // Array of channels IDs that are ignored. | ||
}); | ||
|
||
AntiSpam.on("warnEmit", (member) => console.log(`Attempt to warn ${member.user.tag}.`)); | ||
AntiSpam.on("warnAdd", (member) => console.log(`${member.user.tag} has been warned.`)); | ||
AntiSpam.on("kickEmit", (member) => console.log(`Attempt to kick ${member.user.tag}.`)); | ||
AntiSpam.on("kickAdd", (member) => console.log(`${member.user.tag} has been kicked.`)); | ||
AntiSpam.on("banEmit", (member) => console.log(`Attempt to ban ${member.user.tag}.`)); | ||
AntiSpam.on("banAdd", (member) => console.log(`${member.user.tag} has been banned.`)); | ||
AntiSpam.on("dataReset", () => console.log("Module cache has been cleared.")); | ||
|
||
client.on("ready", () => console.log(`Logged in as ${client.user.tag}.`)); | ||
AntiSpam.on('warnAdd', member => console.log(`${member.user.tag} has been warned.`)); | ||
AntiSpam.on('kickAdd', member => console.log(`${member.user.tag} has been kicked.`)); | ||
AntiSpam.on('banAdd', member => console.log(`${member.user.tag} has been banned.`)); | ||
AntiSpam.on('dataReset', () => console.log('Module cache has been cleared.')); | ||
AntiSpam.on('spamThresholdBan', | ||
(member, duplicate) => console.log(`${member.user.tag} Has reached the ban threshold for spamming!`) | ||
); | ||
client.on('ready', () => console.log(`Logged in as ${client.user.tag}.`)); | ||
|
||
client.on("message", (msg) => { | ||
AntiSpam.message(msg); | ||
client.on('message', msg => { | ||
AntiSpam.message(msg); | ||
}); | ||
|
||
client.login("YOUR_SUPER_SECRET_TOKEN"); | ||
client.login('YOUR_SUPER_SECRET_TOKEN'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { EventEmitter } from 'events'; | ||
import { | ||
PermissionResolvable, | ||
Snowflake, | ||
User, | ||
Guild, | ||
TextChannel, | ||
GuildMember, | ||
Message, | ||
DiscordAPIError, | ||
RichEmbed, | ||
Role | ||
} from 'discord.js'; | ||
declare module 'discord-anti-spam' { | ||
export = class AntiSpam extends EventEmitter { | ||
constructor(options?: AntiSpamOptions); | ||
public options: AntiSpamOptions; | ||
public data: AntiSpamData; | ||
|
||
public message(message: Message): Promise<boolean>; | ||
public resetData(): AntiSpamData; | ||
|
||
public on( | ||
event: 'banAdd' | 'kickAdd' | 'warnAdd', | ||
listener: (member: GuildMember) => any | ||
): this; | ||
public on( | ||
event: 'spamThresholdBan' | 'spamThresholdKick' | 'spamThresholdWarn', | ||
listener: (member: GuildMember, duplicateMessages: boolean) => any | ||
): this; | ||
public on( | ||
event: 'error', | ||
listener: ( | ||
message: Message, | ||
error: DiscordAPIError, | ||
type: 'ban' | 'kick' | ||
) => any | ||
): this; | ||
}; | ||
|
||
type AntiSpamData = { | ||
messageCache: { | ||
content: string; | ||
author: Snowflake; | ||
}[]; | ||
users: { | ||
time: number; | ||
id: Snowflake; | ||
}[]; | ||
bannedUsers: Snowflake[]; | ||
kickedUsers: Snowflake[]; | ||
warnedUsers: Snowflake[]; | ||
}; | ||
|
||
type AntiSpamOptions = { | ||
warnThreshold?: number; | ||
banThreshold?: number; | ||
kickThreshold?: number; | ||
maxInterval?: number; | ||
warnMessage?: string | RichEmbed; | ||
banMessage?: string | RichEmbed; | ||
kickMessage?: string | RichEmbed; | ||
maxDuplicatesWarning?: number; | ||
maxDuplicatesBan?: number; | ||
maxDuplicatesKick?: number; | ||
deleteMessagesAfterBanForPastDays?: number; | ||
exemptPermissions?: PermissionResolvable[]; | ||
ignoreBots?: boolean; | ||
verbose?: boolean; | ||
ignoredUsers?: Snowflake[] | ((user: User) => boolean); | ||
ignoredRoles?: (Snowflake | string)[] | ((role: Role) => boolean); | ||
ignoredGuilds?: Snowflake[] | ((guild: Guild) => boolean); | ||
ignoredChannels?: Snowflake[] | ((channel: TextChannel) => boolean); | ||
warnEnabled?: boolean; | ||
kickEnabled?: boolean; | ||
banEnabled?: boolean; | ||
}; | ||
} |
Oops, something went wrong.