refactor: rename drop functions for clarity and update tests
This commit is contained in:
@@ -69,18 +69,18 @@ for (const k of baseResponse) {
|
||||
hyperlinkarray.push(k.file_url);
|
||||
}
|
||||
|
||||
export async function drop() {
|
||||
export async function dropRule() {
|
||||
if (hyperlinkarray.length === 0) {
|
||||
await refresh();
|
||||
return await drop();
|
||||
return await dropRule();
|
||||
}
|
||||
return hyperlinkarray.pop()!;
|
||||
}
|
||||
|
||||
export async function drop5() {
|
||||
export async function dropRule5() {
|
||||
let tmp = "";
|
||||
for (let i = 0; i < 5; i++) {
|
||||
tmp += await drop() + "\n";
|
||||
tmp += await dropRule() + "\n";
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Bot, Message } from "npm:discordeno@18.0.1";
|
||||
import { drop5, drop, refresh } from "./api.ts";
|
||||
import { dropRule5, dropRule, refresh } from "./api.ts";
|
||||
import { logMessage } from "@root/logging.ts";
|
||||
import { defaultString } from "@root/defaultString.ts";
|
||||
|
||||
@@ -13,7 +13,7 @@ export async function rule34MessageHandler(bot: Bot, message: Message) {
|
||||
message.guildId === undefined
|
||||
) {
|
||||
bot.helpers.sendMessage(message.channelId, {
|
||||
content: defaultString(await drop()),
|
||||
content: defaultString(await dropRule()),
|
||||
});
|
||||
}
|
||||
break;
|
||||
@@ -24,7 +24,7 @@ export async function rule34MessageHandler(bot: Bot, message: Message) {
|
||||
message.guildId === undefined
|
||||
) {
|
||||
bot.helpers.sendMessage(message.channelId, {
|
||||
content: defaultString(await drop5()),
|
||||
content: defaultString(await dropRule5()),
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { assert } from "jsr:@std/assert"
|
||||
import {refresh, drop} from "@root/plugins/rule34/api.ts"
|
||||
import { assert } from "jsr:@std/assert";
|
||||
import { dropRule, refresh } from "@root/plugins/rule34/api.ts";
|
||||
|
||||
Deno.test("Test Drop", async() => {
|
||||
await refresh()
|
||||
const link = await drop()
|
||||
assert(link !== "", "Empty String was dropped!")
|
||||
})
|
||||
Deno.test("Test Drop", async () => {
|
||||
await refresh();
|
||||
const link = await dropRule();
|
||||
assert(link !== "", "Empty String was dropped!");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user