Skip to content
This repository has been archived by the owner on Apr 28, 2023. It is now read-only.

Commit

Permalink
feat: TypeScript rewrite (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
minotaa authored Jul 15, 2021
1 parent 8c354bc commit 2524cdc
Show file tree
Hide file tree
Showing 92 changed files with 3,566 additions and 9,022 deletions.
5 changes: 0 additions & 5 deletions .babelrc

This file was deleted.

4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TOKEN=
MONGODB_URI=
DBL_TOKEN=

Empty file modified .github/FUNDING.yml
100644 → 100755
Empty file.
File renamed without changes.
Empty file modified .github/workflows/codeql-analysis.yml
100644 → 100755
Empty file.
2 changes: 2 additions & 0 deletions .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules/
dist/
yarn-error.log
.env
json.sqlite
Empty file modified .vscode/extensions.json
100644 → 100755
Empty file.
Empty file added .vscode/settings.json
Empty file.
674 changes: 0 additions & 674 deletions LICENSE

This file was deleted.

Empty file modified README.md
100644 → 100755
Empty file.
6,603 changes: 0 additions & 6,603 deletions package-lock.json

This file was deleted.

57 changes: 19 additions & 38 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,55 +1,36 @@
{
"name": "@minota/wushi",
"version": "2.2.0",
"description": "wushi is a social discord bot which helps spice up communities.",
"name": "wushi",
"version": "3.0.0",
"description": "wushi is a social bot written in TypeScript.",
"main": "src/bot.js",
"scripts": {
"start": "npx nodemon --exec babel-node src/bot.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/xMinota/wushi.git"
},
"keywords": [
"wushi",
"discord",
"typescript",
"chatbot",
"chat",
"bot"
],
"author": "Minota",
"repository": "https://github.com/wushi-bot/wushi",
"author": "Minota <[email protected]>",
"license": "GPL-3.0",
"bugs": {
"url": "https://github.com/xMinota/wushi/issues"
},
"homepage": "https://github.com/xMinota/wushi#readme",
"private": false,
"dependencies": {
"@aero/centra": "^1.0.6",
"@babel/core": "^7.11.6",
"@babel/node": "^7.10.5",
"@babel/preset-env": "^7.11.5",
"@types/ws": "^7.4.5",
"axios": "^0.21.1",
"body-parser": "^1.19.0",
"bufferutil": "^4.0.3",
"canvas": "^2.6.1",
"canvas-constructor": "^3.2.0",
"chalk": "^4.1.0",
"canvas": "^2.8.0",
"canvas-constructor": "3.2.0",
"chalk": "^4.1.1",
"dblapi.js": "^2.4.1",
"discord.js-light": "github:timotejroiko/discord.js-light",
"dotenv": "^8.2.0",
"erlpack": "github:discord/erlpack",
"discord.js": "^13.0.0-dev.03d3a5cdde5492433d27bbfe46afe0ebf2de5904",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"moment": "^2.29.1",
"moment-duration-format": "^2.3.2",
"ms": "^2.1.3",
"path": "^0.12.7",
"quick.db": "^7.1.3",
"romanize-number": "^1.0.1",
"sodium": "^3.0.2",
"timeago.js": "^4.0.2",
"tinycolor2": "^1.4.2",
"urban-dictionary": "^3.0.0",
"utf-8-validate": "^5.0.4",
"zlib-sync": "^0.1.7"
"urban-dictionary": "^3.0.1"
},
"devDependencies": {
"@types/node": "^15.12.5",
"mongoose": "^5.13.2",
"typescript": "^4.3.4"
}
}
21 changes: 0 additions & 21 deletions src/bot.js

This file was deleted.

19 changes: 19 additions & 0 deletions src/bot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Client from './classes/Client'
import Database from './database'
import 'dotenv/config'
import { runPetChecks, runUnvoteChecks } from './utils/economy'

const intents = ['GUILDS', 'GUILD_MESSAGES', 'GUILD_MEMBERS', 'GUILD_PRESENCES']

const self = new Client({
fetchAllMembers: true,
intents: intents
})

new Database()

runPetChecks(self)
runUnvoteChecks(self)

self.load()
self.start(process.env.TOKEN!!)
46 changes: 25 additions & 21 deletions src/structs/client.js → src/classes/Client.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
import { Client, Collection } from 'discord.js-light'
import { readdir, readdirSync } from 'fs'
import { Client, Collection } from 'discord.js'
//import TwitchMonitor from './TwitchMonitor'
import Logger from '../utils/logger'
import { readdirSync, readdir } from 'fs'
import path from 'path'
import { Logger } from '../utils/logger'

import 'dotenv/config'
export default class Bot extends Client {

class Bot extends Client {
constructor (options) {
owners: array
commands: any
aliases: any
cooldowns: any
logger: Logger
version: string

constructor (options: any) {
super(options)
this.logger = new Logger()
this.commands = new Collection()
this.aliases = new Collection()
this.cooldowns = new Collection()
this.version = '2.2.0'
this.logger = new Logger()
this.version = '3.0.0'
this.owners = ['488786712206770196']
}

login (token) {
start (token: string) {
super.login(token)
this.logger.log('info', 'Logged into the bot.')
//const Twitch = new TwitchMonitor(this)
//Twitch.start()
return this
}

loadCommands () {
load() {
this.logger.log('info', 'Beginning to check for commands...')
const folders = readdirSync(path.join(__dirname, '..', '/commands/'), { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
Expand All @@ -34,30 +44,24 @@ class Bot extends Client {
command.conf.aliases.forEach(alias => {
this.aliases.set(alias, command.conf.name)
})
this.logger.log('runner', `Registered command ${cmd}`)
this.logger.log('info', `Registered command ${cmd}`)
} catch (e) {
this.logger.log('runner', `Skipped command because it encountered an error: ${e}`)
this.logger.log('error', `Skipped command because it encountered an error: ${e}`)
}
}
}
this.logger.log('info', 'All possible commands have been added.')
}

loadEvents () {
this.logger.log('info', 'Beginning to check for events...')
readdir(path.join(__dirname, '..', '/events/'), (err, files) => {
if (err) return console.error(err)
files.forEach(file => {
if (file.endsWith('.js')) {
const event = require(path.join(__dirname, '..', `/events/${file}`))
const eventName = file.split('.')[0]
this.logger.log('runner', `Added event: ${eventName}`)
this.logger.log('info', `Added event: ${eventName}`)
super.on(eventName, (...args) => event.run(this, ...args))
}
})
})
this.logger.log('info', 'All possible events have been added.')
this.logger.log('info', 'All possible events & commands have been added.')
}
}

module.exports = Bot
}
15 changes: 9 additions & 6 deletions src/structs/command.js → src/classes/Command.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
class Command {
import Client from "../classes/Client"

export default class Command {
conf: any
client: Client
constructor (client, {
name = null,
name = 'none',
description = 'No description provided.',
category = 'Miscellaneous',
usage = 'No usage provided.',
enabled = true,
guildOnly = false,
aliases = [],
aliases = ['none'],
subcommands = [],
cooldown = false
cooldown = -1
}) {
this.client = client
this.conf = { name, description, category, usage, enabled, guildOnly, aliases, cooldown, subcommands }
}
}
module.exports = Command
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Command from '../../structs/command'
import Command from '../../classes/Command'

const clean = text => {
if (typeof (text) === 'string') {
Expand All @@ -12,9 +12,9 @@ class EvalCommand extends Command {
constructor (client) {
super(client, {
name: 'evaluate',
description: '...',
description: 'Evaluate a JavaScript statement',
category: 'Admin',
aliases: ['eval', 'e'],
aliases: ['eval', 'e', 'ev'],
usage: 'eval <statement>',
cooldown: 1
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Command from '../../structs/command'
import { Message, MessageEmbed } from 'discord.js-light'
import utils from '../../utils/utils'
import Command from '../../classes/Command'
import { MessageEmbed } from 'discord.js'
import { getPrefix, removeA } from '../../utils/utils'
import db from 'quick.db'
const cfg = new db.table('config')

Expand Down Expand Up @@ -38,15 +38,15 @@ class AdminRoleCommand extends Command {
} else {
embed.addField('<:info:820704940682510449> Admins', `\`\`\`${roles}\`\`\``)
}
embed.addField('<:role:821012711403683841> How to?', `Add an Admin via \`${utils.getPrefix(msg.guild.id)}adminrole @Admin\`.`)
msg.reply(embed)
embed.addField('<:role:821012711403683841> How to?', `Add an Admin via \`${getPrefix(msg.guild.id)}adminrole @Admin\`.`)
msg.reply({ embeds: [embed] })
return true
} else {
if (!msg.mentions.roles.first()) {
const embed = new MessageEmbed()
.setColor(color)
.addField('<:role:821012711403683841> Role not found', 'You haven\'t inserted a valid role.')
msg.reply(embed)
msg.reply({ embeds: [embed] })
return false
} else {
const role = msg.mentions.roles.first()
Expand All @@ -56,15 +56,15 @@ class AdminRoleCommand extends Command {
const embed = new MessageEmbed()
.setColor(color)
.addField(`<:check:820704989282172960> Success!`, `Successfully added <@&${role.id}> to the Admin Roles.`)
msg.reply(embed)
msg.reply({ embeds: [embed] })
return true
} else {
let i = utils.removeA(admins, role.id)
} else { // @ts-ignore
let i = removeA(admins, role.id)
cfg.set(`${msg.guild.id}.admins`, i)
const embed = new MessageEmbed()
.setColor(color)
.addField(`<:check:820704989282172960> Success!`, `Successfully removed <@&${role.id}> from the Admin Roles.`)
msg.reply(embed)
msg.reply({ embeds: [embed] })
return true
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MessageEmbed } from 'discord.js-light'
import Command from '../../structs/command'
import utils from '../../utils/utils'
import { MessageEmbed } from 'discord.js'
import Command from '../../classes/Command'
import { getPrefix } from '../../utils/utils'
import db from 'quick.db'
const cfg = new db.table('config')

Expand All @@ -18,7 +18,6 @@ class ConfigCommand extends Command {

async run (bot, msg, args) {
const admins = cfg.get(`${msg.guild.id}.admins`) || []
const mods = cfg.get(`${msg.guild.id}.mods`) || []

const disabledCommands = cfg.get(`${msg.guild.id}.disabledCommands`) || []
const disabledModules = cfg.get(`${msg.guild.id}.disabledModules`) || []
Expand All @@ -27,7 +26,7 @@ class ConfigCommand extends Command {
const embed = new MessageEmbed()
.setColor(color)
.setTitle(`<:info:820704940682510449> ${msg.guild.name}'s Configuration`)
.addField('<:slash:820751995824504913> Prefix', `The prefix for this server is \`${utils.getPrefix(msg.guild.id)}\``)
.addField('<:slash:820751995824504913> Prefix', `The prefix for this server is \`${getPrefix(msg.guild.id)}\``)

if (disabledModules.length === 0) {
embed.addField(':newspaper: Disabled Modules', `\`\`\`None\`\`\``)
Expand All @@ -51,17 +50,8 @@ class ConfigCommand extends Command {
})
embed.addField('<:role:821012711403683841> Admins', `${adminRoles.join(', ')}`)
}
if (mods.length === 0) {
embed.addField('<:role:821012711403683841> Mods', `\`\`\`None\`\`\``)
} else {
let modRoles = []
mods.forEach(mod => {
modRoles.push(`<@&${mod}>`)
})
embed.addField('<:role:821012711403683841> Mods', `${modRoles.join(', ')}`)
}

msg.reply(embed)
msg.reply({ embeds: [embed] })
return true
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Command from '../../structs/command'
import Command from '../../classes/Command'
import col from 'tinycolor2'
import { MessageEmbed } from 'discord.js-light'
import { MessageEmbed } from 'discord.js'
import db from 'quick.db'

const cfg = new db.table('config')
Expand All @@ -25,7 +25,7 @@ class EmbedColorCommand extends Command {
const embed = new MessageEmbed()
.setColor(color.toHex())
.addField('<:check:820704989282172960> Success!', `Successfully set your embed color to **#${color.toHex()}**.`)
msg.reply(embed)
msg.reply({ embeds: [embed] })
return true
}
}
Expand Down
Loading

0 comments on commit 2524cdc

Please sign in to comment.