-
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.
move exports out of app.ts to make testing easier whenever I feel lik…
…e adding some tests
- Loading branch information
1 parent
1a87e1b
commit 9cfefe8
Showing
12 changed files
with
83 additions
and
87 deletions.
There are no files selected for viewing
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
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
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,16 @@ | ||
import type { Snowflake } from "discord.js"; | ||
import { db } from "../db/index.ts"; | ||
import { prefixes } from "../db/schema.ts"; | ||
|
||
export const prefixMap = new Map<Snowflake, string>(); | ||
export let botIsLoading = false; | ||
|
||
export function setLoading() { | ||
botIsLoading = true; | ||
} | ||
|
||
export async function init() { | ||
for (const prefixDoc of await db.select().from(prefixes)) { | ||
prefixMap.set(prefixDoc.serverId, prefixDoc.prefix); | ||
} | ||
} |
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,40 @@ | ||
import type { Status } from "../db/types.ts"; | ||
import { db } from "../db/index.ts"; | ||
import { statuses } from "../db/schema.ts"; | ||
import type { Client } from "discord.js"; | ||
import { StatusType } from "../helpers/types.ts"; | ||
import { randomIntFromRange, randomElementFromArray, sleep } from "../helpers/utils.ts"; | ||
|
||
export let statusArr: Status[] = []; | ||
|
||
export async function init(client: Client) { | ||
statusArr = await db.select().from(statuses); | ||
if (statusArr.length) startStatusLoop(client).catch(console.error); | ||
} | ||
|
||
/** | ||
* Starts a loop which periodically changes the status to a random entry in the database | ||
* @param {Client} client Discord client which is used to access the API | ||
*/ | ||
export async function startStatusLoop(client: Client) { | ||
while (true) { | ||
const status = setRandomStatus(client); | ||
if (!status) break; | ||
await sleep(randomIntFromRange(300000, 900000)); // 5m-15m | ||
} | ||
} | ||
|
||
/** | ||
* Grabs a random status from the database and sets it as the status of the bot | ||
* @param client Discord client used to access the API | ||
*/ | ||
function setRandomStatus(client: Client) { | ||
if (!client.user) return console.error("Could not set status, client user is undefined"); | ||
const randStatus = randomElementFromArray(statusArr); | ||
|
||
return client.user.setActivity({ | ||
name: randStatus.type !== "CUSTOM" ? randStatus.status : "Custom status", | ||
state: randStatus.type === "CUSTOM" ? randStatus.status : undefined, | ||
type: StatusType[randStatus.type], | ||
}); | ||
} |
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