forked from lavgup/Wiki-Utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 553c596
Showing
32 changed files
with
1,425 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"commonjs": true, | ||
"es2020": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"parserOptions": { | ||
"ecmaVersion": 2019, | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"arrow-spacing": [ | ||
"error", | ||
{ | ||
"before": true, | ||
"after": true | ||
} | ||
], | ||
"brace-style": [ | ||
"error", | ||
"1tbs", | ||
{ | ||
"allowSingleLine": true | ||
} | ||
], | ||
"comma-dangle": [ | ||
"error", | ||
"never" | ||
], | ||
"comma-spacing": "error", | ||
"eqeqeq": [ | ||
"error", | ||
"smart" | ||
], | ||
"func-call-spacing": "error", | ||
"line-comment-position": "error", | ||
"prefer-const": "error", | ||
"prefer-destructuring": "error", | ||
"no-array-constructor": "error", | ||
"no-dupe-else-if": "error", | ||
"no-duplicate-imports": "error", | ||
"no-extra-semi": "error", | ||
"no-inline-comments": "error", | ||
"no-invalid-regexp": "error", | ||
"no-invalid-this": "error", | ||
"no-lonely-if": "error", | ||
"no-new": "error", | ||
"no-new-object": "error", | ||
"no-new-wrappers": "error", | ||
"no-return-await": "error", | ||
"no-self-compare": "error", | ||
"no-undef-init": "error", | ||
"no-unneeded-ternary": "error", | ||
"no-unreachable": "error", | ||
"no-useless-constructor": "error", | ||
"no-unused-vars": "off", | ||
"prefer-regex-literals": [ | ||
"error", | ||
{ | ||
"disallowRedundantWrapping": true | ||
} | ||
], | ||
"prefer-spread": "error", | ||
"prefer-template": "error", | ||
"require-await": "error", | ||
"semi": "error", | ||
"semi-style": "error", | ||
"space-before-blocks": "error", | ||
"use-isnan": "error", | ||
"valid-typeof": "error", | ||
"quotes": [ | ||
"error", | ||
"single", | ||
{ | ||
"avoidEscape": true, | ||
"allowTemplateLiterals": true | ||
} | ||
] | ||
} | ||
} |
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,3 @@ | ||
node_modules/ | ||
pnpm-lock.yaml | ||
.idea/ |
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,3 @@ | ||
tasks: | ||
- init: npm install | ||
command: npm run start |
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,49 @@ | ||
# Wiki Utilities | ||
Wiki Utilities is a Discord bot, which allows wiki (think Fandom, Wikipedia) admins to take administrative actions, such as deleting, moving, protecting pages and more, through Discord. As Wiki Utilities requires credentials, it is a self-hosted bot, meaning you need to host it yourself to use it. | ||
|
||
### Features | ||
* Blocking users. | ||
* Listing pages in a category. | ||
* Deleting pages. | ||
* Editing pages. | ||
* Moving (i.e. renaming) pages. | ||
* Modifying the protection levels of pages. | ||
* Undeleting (i.e. restoring) pages. | ||
|
||
Upcoming: | ||
|
||
Integration with [RcGcDw](https://gitlab.com/piotrex43/RcGcDw/) (see [#110](https://gitlab.com/piotrex43/RcGcDw/-/issues/110)), allowing admins to lazily react to log messages with emojis, to either block the user, revert the edit, or delete the page. | ||
|
||
### Installing | ||
1. Clone this repo to your machine by running `git clone https://github.com/Sidemen19/Wiki-Utilities.git`. | ||
2. Go to the Discord developer's website while you are logged in to your Discord account [here](https://discordapp.com/developers/applications/). | ||
* Create a new application. | ||
* Copy the Client ID. | ||
* Next, add a Bot (NOTE - you need to make the bot private (meaning only you can invite it to servers), by toggling the switch). | ||
|
||
3. Get the bot's token from the Bot page, copy it, and paste it into the `token` key of [config.json](config.json). | ||
4. Invite Wiki Utilities to a server, by going to `https://discord.com/oauth2/authorize?client_id=INSERT_CLIENT_ID_HERE&scope=bot&permissions=330816`. | ||
5. Install required dependencies, using `pnpm install` or `npm install`. | ||
6. Get the bot online by running `node .` in the root directory. | ||
|
||
### Configuration | ||
All configuration options are stored in [config.json](config.json). | ||
|
||
* `token`: The token of the bot. Get this by following the above instructions. | ||
* `prefixes`: An array of all the prefixes the bot recognises. Defaults to just `wu!`. | ||
* `owners`: An array of all the owners of the bot. Put your Discord ID here, and any others if you want. | ||
* `wiki` | ||
* `url`: The URL to the wiki. Example: `https://community.fandom.com` | ||
* `allowed_roles`: An array of role IDs, the members of it will be able to take administrative wiki actions. (NOTE: give this only to a trusted role, this is basically giving admin rights to whoever is in this role.) | ||
* `blacklisted_users`: An array of user IDs, this overrides `allowed_roles`, removing the right from any untrustworthy users. | ||
* `rcgcdw_extension` (not completed yet) | ||
* `enabled`: Whether the extension is enabled or not. | ||
* `channel_id`: The channel ID of the webhook. | ||
* `emojis`: Any custom emojis to use when reacting, instead of the default regional indicators. | ||
* `credentials` (these must be obtained from `Special:BotPasswords`) | ||
* `username`: The username. (it is recommended to use a separate bot account, and give that admin rights, instead of your main account). | ||
* `password`: The password. | ||
|
||
|
||
### Support | ||
https://discord.com/invite/2ZjJbBJ |
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,27 @@ | ||
{ | ||
"token": "", | ||
"prefixes": ["wu!"], | ||
"owners": [""], | ||
"wiki": { | ||
"url": "", | ||
"allowed_roles": [""], | ||
"blacklisted_users": [], | ||
"rcgcdw_extension": { | ||
"enabled": false, | ||
"channel_id": "", | ||
"emojis": { | ||
"delete": "\uD83C\uDDE9", | ||
"revert": "\uD83C\uDDF7", | ||
"block": "\uD83C\uDDE7" | ||
} | ||
}, | ||
"user_map": { | ||
"enabled": true, | ||
"": "" | ||
}, | ||
"credentials": { | ||
"username": "", | ||
"password": "" | ||
} | ||
} | ||
} |
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,39 @@ | ||
{ | ||
"name": "wiki-utilities", | ||
"version": "1.0.0", | ||
"description": "Discord bot for taking administrative actions on a Fandom wiki through Discord.", | ||
"main": "src/bot/index.js", | ||
"scripts": { | ||
"start": "node .", | ||
"lint": "eslint .", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"engines": { | ||
"node": "12.x", | ||
"pnpm": ">=3" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Sidemen19/Wiki-Utilities.git" | ||
}, | ||
"keywords": [ | ||
"discord", | ||
"discord-bot", | ||
"bot", | ||
"wiki", | ||
"fandom", | ||
"mediawiki" | ||
], | ||
"author": "Sidemen19", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@sidemen19/mediawiki.js": "^1.0.0", | ||
"common-tags": "^1.8.0", | ||
"discord-akairo": "^8.1.0", | ||
"discord.js": "^12.4.1", | ||
"got": "^11.8.0" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^7.12.1" | ||
} | ||
} |
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,83 @@ | ||
const Command = require('../../structs/Command'); | ||
|
||
class HelpCommand extends Command { | ||
constructor() { | ||
super('help', { | ||
aliases: ['help', 'halp', 'h'], | ||
description: { | ||
content: 'Sends information on the bot\'s commands.', | ||
usages: ['', '[command]'], | ||
examples: ['', 'tag'] | ||
}, | ||
category: 'Utilities', | ||
clientPermissions: ['EMBED_LINKS'], | ||
args: [ | ||
{ | ||
id: 'command', | ||
type: 'commandAlias' | ||
} | ||
] | ||
}); | ||
} | ||
|
||
exec(message, { command }) { | ||
const embed = { | ||
author: {}, | ||
fields: [], | ||
color: 'YELLOW' | ||
}; | ||
const [prefix] = this.handler.prefix(message); | ||
|
||
if (command) { | ||
embed.author.name = `${this.client.util.capitalise(command.aliases[0])} Command Help`; | ||
embed.author.icon_url = this.client.user.displayAvatarURL(); | ||
embed.description = command.description.content || 'No description provided.'; | ||
|
||
if (command.aliases && command.aliases.length > 1) { | ||
embed.fields.push({ | ||
name: 'Aliases', | ||
value: command.aliases.slice(1).join('\n') | ||
}); | ||
} | ||
|
||
if (command.description.usages && command.description.usages.length) { | ||
embed.fields.push({ | ||
name: 'Usages', | ||
value: command.description.usages.map(usage => `${prefix}${command.aliases[0]} ${this.formatUsage(usage)}`).join('\n') | ||
}); | ||
} | ||
|
||
if (command.description.examples && command.description.examples.length) { | ||
embed.fields.push({ | ||
name: 'Examples', | ||
value: command.description.examples.map(example => `${prefix}${command.aliases[0]} ${example}`).join('\n') | ||
}); | ||
} | ||
} else { | ||
embed.description = `A list of all available commands.\nFor information on a specific command, send \`${prefix}${this.aliases[0]} <command>\``; | ||
|
||
for (const category of this.handler.categories.values()) { | ||
const commands = category | ||
.filter(cmd => cmd.aliases.length > 0 && !cmd.ownerOnly) | ||
.map(cmd => `\`${cmd.aliases[0]}\``) | ||
.join(' '); | ||
if (!commands.length) continue; | ||
|
||
embed.fields.push({ | ||
name: `${category.id}`, | ||
value: commands | ||
}); | ||
} | ||
} | ||
|
||
return message.util.send({ embed: embed }); | ||
} | ||
|
||
formatUsage(usage) { | ||
return usage | ||
.replace(/<[^>]+>/g, '**$&**') | ||
.replace(/\[[^\]]+]/g, '*$&*'); | ||
} | ||
} | ||
|
||
module.exports = HelpCommand; |
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,21 @@ | ||
const Command = require('../../structs/Command'); | ||
|
||
class PingCommand extends Command { | ||
constructor() { | ||
super('ping', { | ||
aliases: ['ping'], | ||
description: { | ||
content: 'Gets the ping of the bot.' | ||
}, | ||
category: 'Utilities' | ||
}); | ||
} | ||
|
||
async exec(message, args) { | ||
const ping = await message.util.send(`:heartbeat: ${this.client.ws.ping}`); | ||
const RTT = (ping.editedAt || ping.createdAt) - (message.editedAt || message.createdAt); | ||
await ping.edit(`${ping}ms\n:stopwatch: ${RTT}ms`); | ||
} | ||
} | ||
|
||
module.exports = PingCommand; |
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,59 @@ | ||
const { stripIndents } = require('common-tags'); | ||
const Command = require('../../structs/Command'); | ||
const { Listener, Inhibitor, Argument } = require('discord-akairo'); | ||
|
||
class ReloadCommand extends Command { | ||
constructor() { | ||
super('reload', { | ||
aliases: ['reload', 'rl'], | ||
description: { | ||
content: 'Reloads a module.', | ||
usages: ['[command]'], | ||
examples: ['blacklist', ''] | ||
}, | ||
category: 'Utilities', | ||
ownerOnly: true, | ||
args: [ | ||
{ | ||
id: 'module', | ||
type: Argument.union( | ||
'command', | ||
'commandAlias', | ||
'listener', | ||
'inhibitor' | ||
), | ||
prompt: { | ||
start: message => `${message.author}, which module do you wish to reload?`, | ||
retry: message => `${message.author}, that doesn't look like a valid module!` | ||
} | ||
} | ||
] | ||
}); | ||
} | ||
|
||
exec(message, { module }) { | ||
try { | ||
const reloaded = module.reload(); | ||
|
||
let type; | ||
if (reloaded instanceof Command) { | ||
type = 'command'; | ||
} else if (reloaded instanceof Listener) { | ||
type = 'listener'; | ||
} else if (reloaded instanceof Inhibitor) { | ||
type = 'inhibitor'; | ||
} | ||
|
||
return message.util.send(`Successfully reloaded ${type} **${reloaded.id}**.`); | ||
} catch (err) { | ||
return message.util.send(stripIndents` | ||
Something went wrong. | ||
\`\`\`apache | ||
${err.message} | ||
\`\`\` | ||
`); | ||
} | ||
} | ||
} | ||
|
||
module.exports = ReloadCommand; |
Oops, something went wrong.