-
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.
Merge pull request #13 from tannnxr/dev
Dev
- Loading branch information
Showing
9 changed files
with
253 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,65 @@ | ||
import { | ||
ChatInputCommandInteraction, | ||
GuildMember, | ||
PermissionFlagsBits, | ||
SlashCommandBuilder, | ||
} from "discord.js"; | ||
import { LogType, Logger } from "../../utils/logging"; | ||
import mysql from 'mysql'; | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
async function timeOutUser(member: GuildMember, time: number, reason: string) { | ||
await member.timeout(time * 60 * 1000, reason); | ||
} | ||
|
||
async function addWarnToRecord( | ||
db: mysql.Connection, | ||
mod: GuildMember, | ||
user: GuildMember, | ||
reason: string | ||
) { | ||
const query = 'INSERT INTO mod_actions (userid, actiontype, moderatorid, reason) VALUES (?, ?, ?, ?)'; | ||
const values = [user.user.id, 'warn', mod.user.id, reason]; | ||
|
||
return new Promise((resolve, reject) => { | ||
db.query(query, values, (error, results) => { | ||
if (error) { | ||
return reject(error); | ||
} | ||
resolve(results); | ||
}); | ||
}); | ||
} | ||
|
||
function connectToDatabase() { | ||
return mysql.createConnection({ | ||
user: process.env.DB_USER || 'root', | ||
password: process.env.DB_PASSWORD || 'popcornpanties236P!', | ||
host: process.env.DB_HOST || 'localhost', | ||
database: process.env.DB_NAME || 'shork_db', | ||
}); | ||
} | ||
|
||
export default { | ||
data: new SlashCommandBuilder() | ||
.setName("ban") | ||
.setDescription("Ban a user.") | ||
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers) | ||
.addMentionableOption(option => | ||
option | ||
.setName("user") | ||
.setDescription("The user to ban.") | ||
.setRequired(true) | ||
) | ||
.addStringOption(option => | ||
option | ||
.setName("reason") | ||
.setDescription("The reason you're banning the user for") | ||
.setRequired(true) | ||
), | ||
|
||
async execute(interaction: ChatInputCommandInteraction) { | ||
} | ||
}; |
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,46 +1,103 @@ | ||
import { | ||
ChatInputCommandInteraction, | ||
GuildMember, | ||
PermissionFlagsBits, | ||
SlashCommandBuilder, | ||
SlashCommandMentionableOption, | ||
SlashCommandStringOption, | ||
} from "discord.js"; | ||
import { LogType, Logger } from "../../utils/logging"; | ||
import mysql from 'mysql'; | ||
import dotenv from 'dotenv'; | ||
|
||
import { shorkCache } from "../../db/cache"; | ||
dotenv.config({ | ||
path: 'S:\\shork\\.env' | ||
}); | ||
|
||
async function timeOutUser(member: GuildMember, time: number, reason: string) { | ||
await member.timeout(time * 60 * 1000, reason); | ||
} | ||
|
||
async function addWarnToRecord( | ||
db: mysql.Connection, | ||
mod: GuildMember, | ||
user: GuildMember, | ||
reason: string | ||
) { | ||
const query = 'INSERT INTO mod_actions (userid, actiontype, moderatorid, reason) VALUES (?, ?, ?, ?)'; | ||
const values = [user.user.id, 'warn', mod.user.id, reason]; | ||
|
||
return new Promise((resolve, reject) => { | ||
db.query(query, values, (error, results) => { | ||
if (error) { | ||
return reject(error); | ||
} | ||
resolve(results); | ||
}); | ||
}); | ||
} | ||
|
||
function connectToDatabase() { | ||
return mysql.createConnection({ | ||
user: process.env.DB_USER || 'root', | ||
password: process.env.SQL_PASSWORD, | ||
host: process.env.DB_HOST || 'localhost', | ||
database: process.env.DB_NAME || 'shork_db', | ||
}); | ||
} | ||
|
||
export default { | ||
data: new SlashCommandBuilder() | ||
.setName("warn") | ||
.setDescription("Warn a user.") | ||
.setDefaultMemberPermissions(PermissionFlagsBits.ManageChannels) | ||
.addMentionableOption((option) => | ||
.addMentionableOption(option => | ||
option | ||
.setName("user") | ||
.setDescription("The user to warn.") | ||
.setRequired(true) | ||
) | ||
.addStringOption((option) => | ||
.addStringOption(option => | ||
option | ||
.setName("reason") | ||
.setDescription("The reason you're warning the user for") | ||
.setRequired(false) | ||
) | ||
) | ||
.setDefaultMemberPermissions(PermissionFlagsBits.KickMembers), | ||
|
||
async execute(interaction: ChatInputCommandInteraction) { | ||
const logger = new Logger(__filename, LogType.DEBUG); | ||
|
||
const options = interaction.options; | ||
const member = options.getMentionable("user"); | ||
const reason = options.getString("reason"); | ||
const db = connectToDatabase(); | ||
|
||
if (await shorkCache.hGetAll('warnings')) { | ||
await shorkCache.hSet('warnings', {}) | ||
} | ||
db.connect(err => { | ||
if (err) { | ||
logger.log(`Error connecting to the database: ${err.stack}`); | ||
if (interaction.isRepliable()) { | ||
interaction.reply(`Error connecting to the database.`); | ||
} | ||
return; | ||
} | ||
logger.log(`Connected to database with thread ID: ${db.threadId}`); | ||
}); | ||
|
||
const warnings = await shorkCache.hGetAll('warnings') | ||
const options = interaction.options; | ||
const member = options.getMentionable("user") as GuildMember; | ||
const reason = options.getString("reason") || "No reason provided"; | ||
|
||
console.log(warnings) | ||
try { | ||
await addWarnToRecord(db, interaction.member as GuildMember, member, reason); | ||
// await timeOutUser(member, 5, reason); | ||
|
||
if (interaction.isRepliable()) { | ||
interaction.reply(`${member.user.username} has been warned for ${reason}`); | ||
} | ||
} catch (error) { | ||
logger.log(`Error adding warning to record: ${error}`); | ||
if (interaction.isRepliable()) { | ||
interaction.reply(`There was an error warning ${member.user.username}. Please try again later.`); | ||
} | ||
} finally { | ||
db.end(); | ||
logger.log('Exited db', LogType.DEBUG) | ||
} | ||
}, | ||
}; |
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,4 +1,7 @@ | ||
{ | ||
"clientId": "1230659817077604442", | ||
"guildId": "1195155703489384579" | ||
"guildId": "1195155703489384579", | ||
"moderation": { | ||
"baseTimeout": "15" | ||
} | ||
} |
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,6 @@ | ||
interface ModAction { | ||
userid: string, | ||
actiontype: string, | ||
moderatorid: string, | ||
reason: string | ||
} |
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,12 @@ | ||
CREATE TABLE mod_actions( | ||
userid text, | ||
actiontype text, | ||
moderatorid text, | ||
reason text | ||
); | ||
|
||
CREATE TABLE user_levels( | ||
userid text, | ||
xp int, | ||
lvl int | ||
); |
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