Skip to content

Commit

Permalink
fixed broken command handler thanks to rome lint
Browse files Browse the repository at this point in the history
  • Loading branch information
raluvy95 committed Jun 10, 2023
1 parent 6e6b780 commit 6294a95
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 83 deletions.
3 changes: 2 additions & 1 deletion rome.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"recommended": true
},
"suspicious": {
"noExplicitAny": "off"
"noExplicitAny": "off",
"noAssignInExpressions": "off"
},
"complexity": {
"noExtraSemicolon": "error"
Expand Down
28 changes: 15 additions & 13 deletions src/client/Client.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { CommandClient, GeneratorFunctionReturn, Message, TextableChannel } from "eris";
import { CmdStatDB, LevelDB, MovDB, SettingsDB, UserDB } from "./Database";
import { readdirSync } from "fs";
import { MovCommand } from "./Command";
import { MovPlugin } from "./Plugin";
import { Collection } from "@discordjs/collection";
import { ISettingsDB, IUserDB } from "../interfaces/database";
import { CommandClient, GeneratorFunctionReturn, Message, TextableChannel } from 'eris';
import { CmdStatDB, LevelDB, MovDB, SettingsDB, UserDB } from './Database';
import { readdirSync } from 'fs';
import { MovCommand } from './Command';
import { MovPlugin } from './Plugin';
import { Collection } from '@discordjs/collection';
import { ISettingsDB, IUserDB } from '../interfaces/database';

export interface ClientDatabase {
level: MovDB
Expand Down Expand Up @@ -172,8 +172,8 @@ class Mov extends CommandClient {
if (msg.mentions.includes(this.user) && msg.type === 0) {
const userPref = await this.database.user.get<IUserDB>(msg.author.id);
const server = await this.database.settings.get<ISettingsDB>(msg.guildID!);
const responseU = userPref?.prefix ? `Your user prefix is \`${userPref.prefix}\`` : "";
const responseS = server?.prefix ? `The bot's prefix is \`${server.prefix}\`` : "";
const responseU = userPref?.prefix ? `Your user prefix is \`${userPref.prefix}\`` : '';
const responseS = server?.prefix ? `The bot's prefix is \`${server.prefix}\`` : '';
const com = `${responseU} ${responseS}`;
if (com.length === 1) {
client.createMessage(msg.channel.id, "Hello! You can response me with mention! Use `<@" + this.user.username + "> help` to get started!");
Expand All @@ -183,7 +183,7 @@ class Mov extends CommandClient {
}

const userPref = await this.database.user.get<IUserDB>(msg.author.id);
if ((msg.prefix as any) === await this.checkPrefixMod(msg)) {
if ((msg.prefix as any) = await this.checkPrefixMod(msg)) {
this.commandHandler(msg, userPref || undefined);
}
}
Expand All @@ -210,14 +210,16 @@ class Mov extends CommandClient {
const plugins = readdirSync("./build/plugins");
this.on("messageCreate", this.onMessageCreate);
this.on("messageUpdate", (msg, oldMsg) => {
if (oldMsg?.content === msg.content) return;
// rome-ignore lint/suspicious/noDoubleEquals: <explanation>
if (oldMsg?.content == msg.content) return;
this.onMessageCreate(msg);
});
for (const plugin of plugins) {
try {
const plug: { default: MovPlugin<any> } = await import(`../plugins/${plugin}`);

if (typeof plug.default.enable === "boolean" && plug.default.enable) {
if (!plug.default.enable) {
} else {
client.on(plug.default.events.event, plug.default.events.run);
console.log(`Plugin: ${plug.default.name} loaded!`);
}
Expand All @@ -228,7 +230,7 @@ class Mov extends CommandClient {

this.on("ready", () => {
console.log(`Logged as ${this.user.username}#${this.user.discriminator}!`);
});
})
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ client.on("interactionCreate", (i) => {
}
});

unlinkSync("generated.png");
unlinkSync("input.png");

try {
unlinkSync("generated.png");
unlinkSync("input.png");
} catch { }
client.connect();
131 changes: 65 additions & 66 deletions src/utils/reddit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,78 +4,77 @@ import { MovEmbed } from "../client/Embed";
import { Data2, Root } from "../interfaces/reddit";

export async function getSubreddit(
subreddit: string,
opt: {
limit?: number;
includeStickied?: boolean;
noNSFW?: boolean;
mediaOnly?: boolean;
} = { limit: 10, includeStickied: false, noNSFW: true, mediaOnly: false },
subreddit: string,
opt: {
limit?: number;
includeStickied?: boolean;
noNSFW?: boolean;
mediaOnly?: boolean;
} = { limit: 10, includeStickied: false, noNSFW: true, mediaOnly: false },
) {
const now = DateTime.now().toMillis();
const RedditStrikeTime = DateTime.fromISO(
"2023-06-12T01:00:00.123",
).toMillis();
if (now >= RedditStrikeTime) {
throw new Error(
"Reddit API is not longer avaliable due to strike - https://www.reddit.com/r/Save3rdPartyApps/comments/13yh0jf/dont_let_reddit_kill_3rd_party_apps/",
);
}
const anyContent = await fetch(
`https://reddit.com/r/${encodeURIComponent(subreddit)}.json?limit=${
opt.limit
}`,
).then((r) => r.json());
if (anyContent.error) {
throw new Error(`${anyContent.error}: ${anyContent.message}`);
}
let data = (anyContent as Root).data.children.map((m) => m.data);
if (!opt.includeStickied) {
data = data.filter((m) => !m.stickied);
}
if (opt.noNSFW) {
data = data.filter((m) => !m.over_18);
}
if (opt.mediaOnly) {
data = data.filter(
(m) => !!m.url.match(/.*(\.jp(e?)g$|\.png$|\.gif$)/g),
);
}
return data;
const now = DateTime.now().toMillis();
const RedditStrikeTime = DateTime.fromISO(
"2023-06-12T01:00:00.123",
).toMillis();
if (now >= RedditStrikeTime) {
throw new Error(
"Reddit API is not longer avaliable due to black out until the CEO of Reddit will eventually revert this change!. Not even for 2 days!\nRead more at https://www.reddit.com/r/Save3rdPartyApps/comments/13yh0jf/dont_let_reddit_kill_3rd_party_apps/",
);
}
const anyContent = await fetch(
`https://reddit.com/r/${encodeURIComponent(subreddit)}.json?limit=${opt.limit
}`,
).then((r) => r.json());
if (anyContent.error) {
throw new Error(`${anyContent.error}: ${anyContent.message}`);
}
let data = (anyContent as Root).data.children.map((m) => m.data);
if (!opt.includeStickied) {
data = data.filter((m) => !m.stickied);
}
if (opt.noNSFW) {
data = data.filter((m) => !m.over_18);
}
if (opt.mediaOnly) {
data = data.filter(
(m) => !!m.url.match(/.*(\.jp(e?)g$|\.png$|\.gif$)/g),
);
}
return data;
}

export function parseToEmbed(children: Data2) {
const realUTC = (children.created || children.created_utc) * 1000;
const source = `https://reddit.com${children.permalink}`;
const realUTC = (children.created || children.created_utc) * 1000;
const source = `https://reddit.com${children.permalink}`;

const e = new MovEmbed()
.setTitle(`${children.title.slice(0, 255)}`)
.setFooter(`u/${children.author} | r/${children.subreddit}`)
.setURL(source)
.setTimestamp(new Date(realUTC));
const e = new MovEmbed()
.setTitle(`${children.title.slice(0, 255)}`)
.setFooter(`u/${children.author} | r/${children.subreddit}`)
.setURL(source)
.setTimestamp(new Date(realUTC));

if (children.selftext.length > 0) {
e.setDesc(
children.selftext.length >= 2000
? `${children.selftext.slice(0, 2000)}\n[view more](${source})`
: children.selftext,
);
}
if (
!children.url.match(/http(s)?:\/\/.*(\.jpe?g$|\.png$|\.gif$)/g) &&
children.thumbnail.startsWith("http")
) {
e.setThumb(children.thumbnail);
} else {
e.setImage(children.url);
}
if (children.media_metadata) {
e.setImage(Object.values(children.media_metadata)[0].p[0].u);
}
if (children.selftext.length > 0) {
e.setDesc(
children.selftext.length >= 2000
? `${children.selftext.slice(0, 2000)}\n[view more](${source})`
: children.selftext,
);
}
if (
!children.url.match(/http(s)?:\/\/.*(\.jpe?g$|\.png$|\.gif$)/g) &&
children.thumbnail.startsWith("http")
) {
e.setThumb(children.thumbnail);
} else {
e.setImage(children.url);
}
if (children.media_metadata) {
e.setImage(Object.values(children.media_metadata)[0].p[0].u);
}

if (children.is_video) {
e.setDesc(`[Click to see video](${children.url})`);
}
if (children.is_video) {
e.setDesc(`[Click to see video](${children.url})`);
}

return e;
return e;
}

0 comments on commit 6294a95

Please sign in to comment.