Skip to content

Commit

Permalink
Fix scheduler, only repeat items once used items reaches 60%
Browse files Browse the repository at this point in the history
  • Loading branch information
natereprogle committed Dec 3, 2023
1 parent 6abba87 commit cbd2d4b
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 84 deletions.
41 changes: 41 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

85 changes: 42 additions & 43 deletions src/constants/desksAndChairsFacts.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
export enum desksAndChairsFacts {
n1 = "The average person uses a desk at least once in their life",
n2 = "I saw a desk at IKEA once",
n3 = "The average desk is not a sentient being (or is it?)",
n4 = "Some desks are really cool",
n5 = "Desks are real",
n6 = "desk",
n7 = "There is usually at least one desk in a school",
n8 = "There is probably a desk in your house",
n9 = "desks aren't typically edible",
n10 = "You can put things on a desk",
n11 = "Some desks are green",
n12 = "My desk isn't green",
n13 = '"Desk" is a word in english',
n14 = "Some desks are made of wood",
n15 = "Some desks are made of metal",
n16 = "SOME DESKS ARE MADE OF DESK!!",
n17 = `The word "desk" doesn't sound like a word to me anymore because i've said it so many times in my head`,
n18 = "Desks are quite similar to dogs, as they both often have four legs",
n19 = `I own a desk and i'm going to name it "desk"`,
n20 = "Desks > tables",

n21 = "I wrote all these facts while sitting in a chair!",
n22 = "The chair has many different forms",
n23 = "Some chairs are kinda mean tbh (though some are nice)",
n24 = "I don't know who invented the chair",
n25 = "The haters told me I couldn't own a pet chair. I proved them WRONG!",
n26 = "The gaming chair was a revolutionary creation which is currently used by gamers all over the world",
n27 = "Wulfie owns a chair from IKEA",
n28 = '"Crystal" and "chair" both start with the letter "C"',
n29 = "Most people know what a chair is (I think I know what a chair is)",
n30 = "respect the chairs",
n31 = "There is always a possibility that chairs could one day become sentient and try to take over the world!",
n32 = "i really want a flying chair :(",
n33 = "i saw a blue chair at school",
n34 = "I, The LEGENDARY Crystal Bot, dream of one day owning 4529 chairs ",
n35 = "I will 100% support the chairs when they take over the world",
n36 = "people genuinely need to stop using chairs as shopping carts",
n37 = "If you own a chair, you probably breath air",
n38 = `Most people don't know this, but the word "chair" starts with the letter C`,
n39 = "Some chairs could technically be used as a form of transport",
n40 = "this fact about chairs probably made you think about chairs"
}
export const desksAndChairsFacts = [
"The average person uses a desk at least once in their life",
"I saw a desk at IKEA once",
"The average desk is not a sentient being (or is it?)",
"Some desks are really cool",
"Desks are real",
"desk",
"There is usually at least one desk in a school",
"There is probably a desk in your house",
"desks aren't typically edible",
"You can put things on a desk",
"Some desks are green",
"My desk isn't green",
'"Desk" is a word in english',
"Some desks are made of wood",
"Some desks are made of metal",
"SOME DESKS ARE MADE OF DESK!!",
`The word "desk" doesn't sound like a word to me anymore because i've said it so many times in my head`,
"Desks are quite similar to dogs, as they both often have four legs",
`I own a desk and i'm going to name it "desk"`,
"Desks > tables",
"I wrote all these facts while sitting in a chair!",
"The chair has many different forms",
"Some chairs are kinda mean tbh (though some are nice)",
"I don't know who invented the chair",
"The haters told me I couldn't own a pet chair. I proved them WRONG!",
"The gaming chair was a revolutionary creation which is currently used by gamers all over the world",
"Wulfie owns a chair from IKEA",
'"Crystal" and "chair" both start with the letter "C"',
"Most people know what a chair is (I think I know what a chair is)",
"respect the chairs",
"There is always a possibility that chairs could one day become sentient and try to take over the world!",
"i really want a flying chair :(",
"i saw a blue chair at school",
"I, The LEGENDARY Crystal Bot, dream of one day owning 4529 chairs ",
"I will 100% support the chairs when they take over the world",
"people genuinely need to stop using chairs as shopping carts",
"If you own a chair, you probably breath air",
`Most people don't know this, but the word "chair" starts with the letter C`,
"Some chairs could technically be used as a form of transport",
"this fact about chairs probably made you think about chairs",
]
8 changes: 1 addition & 7 deletions src/constants/microwaveThings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
export enum microwaveThings {
n1 = "Phone",
n2 = "Car",
n3 = "Roblox account",
n4 = "Shoes",
n5 = "Nintendo switch"
}
export const microwaveThings = ["Phone", "Car", "Roblox account", "Shoes", "Nintendo switch"]
9 changes: 1 addition & 8 deletions src/constants/randomReplies.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
export enum randomReplies {
n1 = "Could you repeat that?",
n2 = "Wow",
n3 = "My iPhone is green",
n4 = "wdym",
n5 = "skill issue",
n6 = "💀"
}
export const randomReplies = ["Could you repeat that?", "Wow", "My iPhone is green", "wdym", "skill issue", "💀"]
75 changes: 49 additions & 26 deletions src/modules/utils/messageScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,63 @@ import { getConfig } from "../config"
import { microwaveThings } from "../../constants/microwaveThings"
import { desksAndChairsFacts } from "../../constants/desksAndChairsFacts"

const config = getConfig()

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export async function loadSchedules(client: CrystalClient): Promise<void> {
// schedule.scheduleJob('26 8 * * 5', microwave)
schedule.scheduleJob('26 8 * * 5', microwave)
schedule.scheduleJob('34 13 * * 1,4,6', desksAndChairs)
schedule.scheduleJob('12 5 * * 1,4,6', desksAndChairs)
schedule.scheduleJob('56 16 * * 1,4,6', desksAndChairs)
schedule.scheduleJob('0 12 */8 * *', polls)

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
function enumRandomIndex(enumName: any) {
const values = Object.values(enumName);
const randomIndex = Math.floor(Math.random() * values.length);
return values[randomIndex] as string
const config = getConfig()
const usedMicrowaveItems: string[] = []
const usedDeskFacts: string[] = []

function randomItemFromArray(list: string[]): string {
return list[Math.floor(Math.random() * list.length)]
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async function microwave() {
const randomItem = enumRandomIndex(microwaveThings)
const channel = await client.channels.fetch(config.channelId) as TextChannel
async function microwave(): Promise<void> {
let found: boolean = false
let randomItem: string = ""

if (usedMicrowaveItems.length / microwaveThings.length >= 0.6) {
// This allows us to clear the array while still leaving it a const
usedMicrowaveItems.length = 0
}

while (!found) {
randomItem = randomItemFromArray(microwaveThings)
if (!usedMicrowaveItems.includes(randomItem)) {
usedMicrowaveItems.push(randomItem)
found = true
}
}

const channel = (await client.channels.fetch(config.channelId)) as TextChannel
await channel.send(`Gosh darn it! I forgot my ${randomItem} in the microwave again!`)
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async function desksAndChairs() {
const Fact = enumRandomIndex(desksAndChairsFacts)
const channel = await client.channels.fetch(config.channelId) as TextChannel
await channel.send(Fact)
}
async function desksAndChairs(): Promise<void> {
let found: boolean = false
let randomItem: string = ""

if (usedDeskFacts.length / microwaveThings.length >= 0.6) {
// This allows us to clear the array while still leaving it a const
usedDeskFacts.length = 0
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async function polls() {
while (!found) {
randomItem = randomItemFromArray(desksAndChairsFacts)
if (!usedDeskFacts.includes(randomItem)) {
usedDeskFacts.push(randomItem)
found = true
}
}

const channel = (await client.channels.fetch(config.channelId)) as TextChannel
await channel.send(randomItem)
}

async function polls(): Promise<void> {}

schedule.scheduleJob("26 8 * * 5", microwave)
schedule.scheduleJob("34 13 * * 1,4,6", desksAndChairs)
schedule.scheduleJob("12 5 * * 1,4,6", desksAndChairs)
schedule.scheduleJob("56 16 * * 1,4,6", desksAndChairs)
schedule.scheduleJob("0 12 */8 * *", polls)
}

0 comments on commit cbd2d4b

Please sign in to comment.