Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Commit

Permalink
bugfix, nsfw reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
banner4422 committed Aug 9, 2021
1 parent 2995f82 commit 64148b3
Show file tree
Hide file tree
Showing 19 changed files with 259 additions and 159 deletions.
42 changes: 0 additions & 42 deletions src/commands/admin/nsfw.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/commands/admin/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const command: Command = {
.setTitle(`Server settings for ${message.guild.name}`)
.setTimestamp()
.setColor(`${message.guild.iconURL() ? await urlToColours(message.guild.iconURL({ format: 'png'})) : await urlToColours(client.user.avatarURL({ format: 'png'}))}`)
.addField('NSFW', `${guildData.nsfw ? 'Enabled' : 'Disabled'}`, true)
//.addField('NSFW', `${guildData.nsfw ? 'Enabled' : 'Disabled'}`, true)
.addField('Tiktok', `${guildData.tiktok ? 'Enabled' : 'Disabled'}`, true)
.addField('Media', `${guildData.media ? 'Enabled' : 'Disabled'}`, true)
.addField('Leaderboard', `${guildData.leaderboard ? 'Enabled' : 'Disabled'}`, true)
Expand All @@ -50,7 +50,7 @@ export const command: Command = {
.addField('Mod log channel', `${modLogText}`, true)
.addField('Message log channel', `${msgLogText}`, true)
.addField('Mute role', `${muteRoleDataText}`, true)
.addField(autoRoleData.length > 1 ? 'Auto assigned roles' : 'Auto assigned role', autoRoleData.length ? trim(autoRoleData.map(r => `<@&${r.roleID}>`).join(' | '), 1024) : 'Not configured', true)
.addField(autoRoleData.length > 1 ? 'Auto assigned roles' : 'Auto assigned role', autoRoleData.length ? trim(autoRoleData.map(r => `<@&${r.roleID}>`).join(' | '), 1024) : 'Not configured', false)

return message.channel.send(Embed);
}
Expand Down
8 changes: 6 additions & 2 deletions src/commands/features/gif.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import utf8 from 'utf8'
import database from '../../database/database';
import { initModels, guild } from '../../database/models/init-models';
import * as dotenv from "dotenv";
import { Message } from 'discord.js';
import { Message, TextChannel } from 'discord.js';
dotenv.config();

const tenorAPI = axios.create({
Expand All @@ -22,6 +22,10 @@ export const command: Command = {
return message.channel.send('You need to provide a search input!').then(m => m.delete({timeout: 5000}));
}

if (message.channel.type !== 'text') return

const channelObject = message.channel as TextChannel

initModels(database);

const guildDB = await guild.findOne({raw: true, where: {guildID: message.guild.id}});
Expand All @@ -30,7 +34,7 @@ export const command: Command = {

let query: string;
let filter: string;
if (guildDB.nsfw === false) {
if (channelObject.nsfw === false) {
query = args.join(" ").replace('contentfilter', '');
filter = 'high';
} else {
Expand Down
40 changes: 27 additions & 13 deletions src/commands/features/horoscope.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Command } from '../../interfaces';
import { capitalize, horoSigns, horoSignsLow, urlToColours } from '../../utils';
import database from '../../database/database';
import { initModels, guild, horoscope, horoscopeCreationAttributes} from '../../database/models/init-models';
import { initModels, guild, horoscope, horoscopeCreationAttributes, horoscopeAttributes} from '../../database/models/init-models';
import { Message, MessageEmbed, GuildMember, Util } from 'discord.js';
//const aztroJs = require("aztro-js");
import * as aztroJs from 'aztro-js'
Expand Down Expand Up @@ -361,18 +361,28 @@ export const command: Command = {
}

async function horoList (message: Message) {
const serverRank = await database.query(`
SELECT u.username, u.discriminator, horo.horoscope
interface horoscopeListInterface {
userID: bigint,
username: string,
discriminator: string,
horoscope: horoscopeAttributes
}
const serverRank: Array<horoscopeListInterface> = await database.query(`
SELECT u."userID", u.username, u.discriminator, horo.horoscope
FROM horoscope AS horo
INNER JOIN "user" u on u."userID" = horo."userID"
INNER JOIN "guildMember" gM on u."userID" = gM."userID"
WHERE "guildID" = :guild
GROUP BY u.username, u.discriminator, horo.horoscope
GROUP BY u."userID", u.username, u.discriminator, horo.horoscope
ORDER BY u.username ASC;`, {
replacements: { guild: message.guild.id },
type: QueryTypes.SELECT
});

if (!serverRank.length) {
return message.channel.send(`No horoscopes are saved on this server.`)
}

let currentPage: number = 0;
const embeds = await generateHoroListEmbed(serverRank)
const queueEmbed = await message.channel.send(`Current Page: ${currentPage+1}/${embeds.length}`, embeds[currentPage]);
Expand Down Expand Up @@ -401,37 +411,41 @@ export const command: Command = {
}
})

async function generateHoroListEmbed (data) {
async function generateHoroListEmbed (data: Array<horoscopeListInterface>) {
const embeds = [];
let k = 10;
for(let i =0; i < data.length; i += 10) {
const current = data.slice(i, k);
let j = i;
k += 10;
// det foroven skærer, så det kun bliver 10 pr. page.
const info = current.map(horoscope => `${++j}. **${horoscope.username}#${horoscope.discriminator}:** ${horoscope.horoscope}`).join(`\n`)
const info = current.map(horoscope => `**${++j}.** ${message.guild.members.cache.get(`${horoscope.userID}`)} - ${horoscope.horoscope}`).join(`\n`)
const embed = new MessageEmbed()
.setDescription(`${info}`)
.setColor(message.guild.iconURL() ? `${await urlToColours(message.guild.iconURL({ format: 'png'}))}` : `${await urlToColours(client.user.displayAvatarURL({ format: 'png'}))}`)
.setTitle(`All horoscopes for ${message.guild.name}`)
.setThumbnail(message.guild.iconURL() ? message.guild.iconURL() : '')
.setAuthor(message.guild.iconURL() ? message.guild.name : client.user.username, message.guild.iconURL() ? message.guild.iconURL() : client.user.displayAvatarURL())
.setTimestamp()
// denne funktion skal skubbe siderne
embeds.push(embed)
}
return embeds;
}
}

async function horoSearch (message: Message, query?: string) {
const queryData = await database.query(`
SELECT u.username, u.discriminator, horo.horoscope
interface horoscopeListInterface {
userID: bigint,
username: string,
discriminator: string,
horoscope: horoscopeAttributes
}
const queryData: Array<horoscopeListInterface> = await database.query(`
SELECT u."userID", u.username, u.discriminator, horo.horoscope
FROM horoscope AS horo
INNER JOIN "user" u on u."userID" = horo."userID"
INNER JOIN "guildMember" gM on u."userID" = gM."userID"
WHERE gM."guildID" = :guild AND horo.horoscope::text ILIKE :query
GROUP BY u.username, u.discriminator, horo.horoscope
GROUP BY u."userID", u.username, u.discriminator, horo.horoscope
ORDER BY u.username ASC;`, {
replacements: { guild: message.guild.id, query: '%' + query + '%' },
type: QueryTypes.SELECT
Expand Down Expand Up @@ -469,15 +483,15 @@ export const command: Command = {
}
})

async function generateTagSearchEmbed (data) {
async function generateTagSearchEmbed (data: Array<horoscopeListInterface>) {
const embeds = [];
let k = 10;
for(let i =0; i < data.length; i += 10) {
const current = data.slice(i, k);
let j = i;
k += 10;
// det foroven skærer, så det kun bliver 10 pr. page.
const info = current.map(horoscope => `${++j}. **${horoscope.username}#${horoscope.discriminator}:** ${horoscope.horoscope}`).join(`\n`)
const info = current.map(horoscope => `**${++j}.** ${message.guild.members.cache.get(`${horoscope.userID}`)} - ${horoscope.horoscope}`).join(`\n`)
const embed = new MessageEmbed()
.setDescription(`${info}`)
.setColor(message.guild.iconURL() ? `${await urlToColours(message.guild.iconURL({ format: 'png'}))}` : `${await urlToColours(client.user.displayAvatarURL({ format: 'png'}))}`)
Expand Down
13 changes: 10 additions & 3 deletions src/commands/features/image.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Command } from '../../interfaces';
import database from '../../database/database';
import { initModels, guild } from '../../database/models/init-models';
import { Message } from 'discord.js';
import { Message, TextChannel } from 'discord.js';
const gis: any = require('g-i-s');
//import * as gis from 'g-i-s'

Expand All @@ -12,16 +12,23 @@ export const command: Command = {
description: 'Searches for random images based on the search input',
usage: 'image <search query>',
run: async (client, message, args): Promise<Message> => {
if (!args.length) {
return message.channel.send('You need to provide a search input!').then(m => m.delete({timeout: 5000}));
}

if (message.channel.type !== 'text') return

initModels(database);

const guildDB = await guild.findOne({raw: true, where: {guildID: message.guild.id}});

if (guildDB.media === false) return

const channelObject = message.channel as TextChannel

let query: string;
if (guildDB.nsfw === false) {
query = args.join(" ").replace('#', '') + '&safe=on'
if (channelObject.nsfw === false) {
query = args.join(" ").replace('#', '').replace('&safe=off', '').replace('&safe=on', '') + '&safe=on'
} else {
query = args.join(" ")
}
Expand Down
28 changes: 26 additions & 2 deletions src/commands/features/lastfm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const lastfmAPI = axios.create({
baseURL: "https://ws.audioscrobbler.com/2.0",
params: { api_key: api_key, format: 'json' }
});

/*
let spotifyCred = new SpotifyWebApi({
clientId: process.env.spotifyClientID,
clientSecret: process.env.spotifyClientSecret,
Expand All @@ -43,7 +43,7 @@ async function newToken () {
newToken()
setInterval(newToken, 3600000)

*/
export const command: Command = {
name: 'lastfm',
aliases: ['fm', 'lf'],
Expand Down Expand Up @@ -869,6 +869,10 @@ export const command: Command = {

playData.slice(0, 9);

if (!playData.length) {
return message.channel.send(`No one on this server knows the track ${track} by ${artist}`)
}

const embeds = generateWktEmbed(playData)
await message.channel.send(await embeds);

Expand Down Expand Up @@ -975,6 +979,10 @@ export const command: Command = {

playData.slice(0, 9);

if (!playData.length) {
return message.channel.send(`No one on this server knows the album ${artistAlbum} by ${artist}`)
}

const embeds = generateWkaEmbed(playData)
await message.channel.send(await embeds);

Expand Down Expand Up @@ -1070,6 +1078,10 @@ export const command: Command = {
});

playData.slice(0, 9);

if (!playData.length) {
return message.channel.send(`No one on this server knows the artist ${artistName}`)
}

const embeds = generateWkEmbed(playData)
await message.channel.send(await embeds);
Expand Down Expand Up @@ -1174,6 +1186,10 @@ export const command: Command = {

playData.slice(0, 9);

if (!playData.length) {
return message.channel.send(`No one who uses Bento Bot knows the track ${track} by ${artist}`)
}

const embeds = generateGwktEmbed(playData)
await message.channel.send(await embeds);

Expand Down Expand Up @@ -1278,6 +1294,10 @@ export const command: Command = {

playData.slice(0, 9);

if (!playData.length) {
return message.channel.send(`No one who uses Bento Bot knows the album ${artistAlbum} by ${artist}`)
}

const embeds = generateGwkaEmbed(playData)
await message.channel.send(await embeds);

Expand Down Expand Up @@ -1373,6 +1393,10 @@ export const command: Command = {

playData.slice(0, 9);

if (!playData.length) {
return message.channel.send(`No one who uses Bento Bot knows ${artist}`)
}

const embeds = generateGwkEmbed(playData)
await message.channel.send(await embeds);

Expand Down
14 changes: 7 additions & 7 deletions src/commands/features/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const command: Command = {
aliases: ['t'],
category: 'features',
description: 'Add, delete, search, edit tags, get info about a tag or a list of all tags on a server',
usage: 'tag <add> <tag name> <tag content>\ntag <delete> <tag name>\ntag <edit> <tag name> <tag content being edit>\ntag <info> <tag name>\ntag <list>\ntag <random> [search query]\ntag <rename> <tag name> <new tag name>\ntag <search> <query>\ntag <author> [mention a user or userID]',
usage: 'tag <add> <tag name> <tag content>\ntag <delete> <tag name>\ntag <edit> <tag name> <tag content being edit>\ntag <info> <tag name>\ntag <list>\ntag <random> [search query]\ntag <rename> <tag name> <new tag name>\ntag <search> <query>\ntag <author> [mention a user or userID]\ntag <top>',
run: async (client, message, args): Promise<any> => {

if (!args.length) {
Expand Down Expand Up @@ -139,9 +139,9 @@ export const command: Command = {
}

if (files && text) {
tagContent = `${text}\n${files}`
tagContent = `${Util.escapeMarkdown(text)}\n${files}`
} else if (text && !files) {
tagContent = text
tagContent = Util.escapeMarkdown(text)
} else if (!text && files) {
tagContent = files
} else if (!text && !files) {
Expand All @@ -152,7 +152,7 @@ export const command: Command = {
userID: BigInt(message.author.id),
guildID: BigInt(message.guild.id),
command: tagName,
content: Util.escapeMarkdown(tagContent),
content: tagContent,
count: 0
}

Expand Down Expand Up @@ -216,16 +216,16 @@ export const command: Command = {
}

if (files && text) {
tagContent = `${text}\n${files}`
tagContent = `${Util.escapeMarkdown(text)}\n${files}`
} else if (text && !files) {
tagContent = text
tagContent = Util.escapeMarkdown(text)
} else if (!text && files) {
tagContent = files
} else if (!text && !files) {
return message.channel.send(`You didn't attach any content for the tag \`${tagName}\``)
}

await tag.update({content: Util.escapeMarkdown(tagContent)}, {where: {guildID: tagData.guildID, userID: tagData.userID, command: tagData.command}})
await tag.update({content: tagContent}, {where: {guildID: tagData.guildID, userID: tagData.userID, command: tagData.command}})
return message.channel.send(`The tag \`${tagData.command}\` got updated!\nThe content is now: \`${tagContent}\``)
}

Expand Down
13 changes: 11 additions & 2 deletions src/commands/features/urban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,20 @@ export const command: Command = {

const response = await urbanAPI.get('/define?', {params: {term: query}});

if (!response.data.length) {
if (!response.data.list.length) {
return message.channel.send(`No definition found for \`${query}\`.`);
}

const answer = response.data.list[0]
interface urbanDicInterface {
word: string,
permalink: string,
definition: string,
example: string,
thumbs_up: number,
thumbs_down: number
}

const answer: urbanDicInterface = response.data.list[0]

const exampleEmbed = new MessageEmbed()
.setColor('#1c9fea')
Expand Down
Loading

0 comments on commit 64148b3

Please sign in to comment.