Skip to content

Commit

Permalink
Merge branch 'master' into bun
Browse files Browse the repository at this point in the history
  • Loading branch information
holzmaster committed Dec 13, 2023
2 parents 80de18e + 5d53fad commit dbeb428
Show file tree
Hide file tree
Showing 42 changed files with 1,174 additions and 126 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
show-progress: false
fetch-depth: 0

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: npm
Expand All @@ -36,6 +37,8 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
show-progress: false
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3

Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"editor.defaultFormatter": "biomejs.biome"
},
"cSpell.words": [
"splid",
"proxitok",
"wois",
"bday",
Expand Down
6 changes: 6 additions & 0 deletions backup-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh

TODAY=$(date +"%Y-%m-%d")

mkdir -p backups
sqlite3 storage.db ".backup backups/$TODAY-backup.db"
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/1.0.0/schema.json",
"$schema": "https://biomejs.dev/schemas/1.4.1/schema.json",
"organizeImports": {
"enabled": false
},
Expand Down
Binary file modified bun.lockb
Binary file not shown.
29 changes: 15 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,35 @@
},
"homepage": "https://github.com/NullDev/CSZ-Bot#readme",
"dependencies": {
"@discordjs/voice": "^0.16.0",
"@discordjs/voice": "^0.16.1",
"@resvg/resvg-js": "^2.6.0",
"canvas": "^2.11.2",
"chrono-node": "^2.7.0",
"croner": "^7.0.4",
"discord.js": "^14.13.0",
"chrono-node": "^2.7.3",
"croner": "^7.0.5",
"discord.js": "^14.14.1",
"get-audio-duration": "^4.0.1",
"graphviz-wasm": "^3.0.1",
"instagram-url-direct": "^1.0.13",
"jsdom": "^22.1.0",
"jsdom": "^23.0.1",
"libsodium-wrappers": "^0.7.13",
"minimist": "^1.2.8",
"moment": "^2.29.4",
"pino": "^8.16.1",
"sequelize": "^6.33.0",
"pino": "^8.16.2",
"sequelize": "^6.35.1",
"splid-js": "^1.1.1",
"sqlite3": "~5.1.6"
},
"devDependencies": {
"@biomejs/biome": "^1.3.1",
"@biomejs/biome": "^1.4.1",
"@ffprobe-installer/ffprobe": "^2.1.2",
"@types/jsdom": "^21.1.4",
"@types/minimist": "^1.2.4",
"@types/node": "^20.8.9",
"@types/node-cron": "^3.0.10",
"@types/sqlite3": "^3.1.10",
"@types/jsdom": "^21.1.6",
"@types/minimist": "^1.2.5",
"@types/node": "^20.10.4",
"@types/node-cron": "^3.0.11",
"@types/sqlite3": "^3.1.11",
"concurrently": "^8.2.2",
"pino-pretty": "^10.2.3",
"typescript": "^5.2.2"
"typescript": "^5.3.3"
},
"engines": {
"node": ">=21.1.0"
Expand Down
2 changes: 1 addition & 1 deletion src/commands/aoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const createEmbedFromLeaderBoard = (
) => {
log.info("[AoC] Creating Embed from leaderboard...");

const members = Object.values(lb.members);
const members = Object.values(lb.members).filter(m => m.stars > 0);
members.sort((a, b) => b[order] - a[order]);
const top: discord.EmbedField[] = members.slice(0, 6).map((m, i) => ({
name: `${medals[i]} ${i + 1}. ${getNameString(m, userMap, false)}`,
Expand Down
5 changes: 2 additions & 3 deletions src/commands/boobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,8 @@ export class BoobCommand implements MessageCommand {
`${author.id} wants to measure boob of user ${userToMeasure.id}`,
);

const recentMeasurement = await Boob.fetchRecentMeasurement(
userToMeasure,
);
const recentMeasurement =
await Boob.fetchRecentMeasurement(userToMeasure);

if (recentMeasurement === null) {
log.debug(
Expand Down
5 changes: 2 additions & 3 deletions src/commands/deoida.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ async function deOidaLine(line: string): Promise<string> {
const aussieWordsToReplace = [];

for (const translationCandidate of enumerateAdjacentTokens(tokens)) {
const germanTranslation = await AustrianTranslation.findTranslation(
translationCandidate,
);
const germanTranslation =
await AustrianTranslation.findTranslation(translationCandidate);
if (germanTranslation) {
// This is a rather dumb way of doing this.
// Consider the example from above: "oida der fesche bursch han recht"
Expand Down
4 changes: 2 additions & 2 deletions src/commands/doener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export class DoenerCommand implements MessageCommand {
knives === "1"
? "1 Messerblock"
: knives !== undefined
? `${knives} Messerblöcke`
: undefined;
? `${knives} Messerblöcke`
: undefined;

const boardsStr =
boards !== undefined
Expand Down
5 changes: 4 additions & 1 deletion src/commands/ehre.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@ async function createEhreTable(
function getVote(userInGroups: EhreGroups, voter: string): number {
if (userInGroups.best?.userId === voter) {
return 5;
} else if (userInGroups.middle.map(u => u.userId).includes(voter)) {
}

if (userInGroups.middle.map(u => u.userId).includes(voter)) {
return 2;
}

return 1;
}

Expand Down
12 changes: 8 additions & 4 deletions src/commands/extend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,18 @@ export const run: CommandFunction = async (client, message, args, context) => {
.map(e => e.trim())
.filter(e => e.replace(/\s/g, "") !== "");

if (!additionalPollOptions.length)
if (!additionalPollOptions.length) {
return "Bruder da sind keine Antwortmöglichkeiten :c";
else if (
}

if (
additionalPollOptions.length + oldPollOptionFields.length >
poll.OPTION_LIMIT
)
) {
return `Bruder mit deinen Antwortmöglichkeiten wird das Limit von ${poll.OPTION_LIMIT} überschritten!`;
else if (
}

if (
additionalPollOptions.some(
value => value.length > poll.FIELD_VALUE_LIMIT,
)
Expand Down
7 changes: 3 additions & 4 deletions src/commands/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ensureChatInputCommand } from "../utils/interactionUtils.js";
/**
* Randomly capitalize letters
*/
const transform = function (c: string): string {
const transform = (c: string): string => {
if (c === "ß" || c === "ẞ") return c;
return Math.random() < 0.5 ? c.toLowerCase() : c.toUpperCase();
};
Expand Down Expand Up @@ -96,9 +96,8 @@ export class MockCommand implements MessageCommand, ApplicationCommand {

let replyMessage: Message<boolean> | null = null;
if (isReply) {
replyMessage = await message.channel.messages.fetch(
messageReference,
);
replyMessage =
await message.channel.messages.fetch(messageReference);
if (!hasContent) {
content = replyMessage.content;
}
Expand Down
15 changes: 12 additions & 3 deletions src/commands/nickname.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ export class Nickname implements ApplicationCommand {
await this.updateNickName(member, null);
await cmd.reply("Ok Brudi. Hab alles gelöscht");
return;
} else if (option === "list") {
}

if (option === "list") {
const nicknames = await Nicknames.getNicknames(user.id);
if (nicknames.length === 0) {
await cmd.reply("Ne Brudi für den hab ich keine Nicknames");
Expand All @@ -162,7 +164,9 @@ export class Nickname implements ApplicationCommand {
}):\n${nicknames.map(n => n.nickName).join(", ")}`,
);
return;
} else if (option === "add") {
}

if (option === "add") {
if (!trusted) {
await cmd.reply("Hurensohn. Der Command ist nix für dich.");
return;
Expand All @@ -181,11 +185,14 @@ export class Nickname implements ApplicationCommand {
trusted,
);
// await this.addNickname(command, user);
} else if (option === "delete") {
}

if (option === "delete") {
if (!trusted && !sameuser) {
await cmd.reply("Hurensohn. Der Command ist nix für dich.");
return;
}

// We don't violate the DRY principle, since we're referring to another subcommand object as in the "add" subcmd.
// Code is equal but knowledge differs.
const nickname = cmd.options.getString("nickname", true);
Expand All @@ -197,9 +204,11 @@ export class Nickname implements ApplicationCommand {
);
return;
}

if (member.nickname === nickname) {
await this.updateNickName(member, null);
}

await cmd.reply(
`Ok Brudi. Hab für ${user} ${nickname} gelöscht`,
);
Expand Down
5 changes: 2 additions & 3 deletions src/commands/penis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,8 @@ export class PenisCommand implements MessageCommand {
`${author.id} wants to measure penis of user ${userToMeasure.id}`,
);

const recentMeasurement = await Penis.fetchRecentMeasurement(
userToMeasure,
);
const recentMeasurement =
await Penis.fetchRecentMeasurement(userToMeasure);

if (recentMeasurement === null) {
log.debug(
Expand Down
23 changes: 13 additions & 10 deletions src/commands/poll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,14 @@ export const run: CommandFunction = async (_client, message, args, context) => {

if (!pollOptions.length)
return "Bruder da sind keine Antwortmöglichkeiten :c";
else if (pollOptions.length < 2 && !isExtendable)

if (pollOptions.length < 2 && !isExtendable)
return "Bruder du musst schon mehr als eine Antwortmöglichkeit geben 🙄";
else if (pollOptions.length > OPTION_LIMIT)

if (pollOptions.length > OPTION_LIMIT)
return `Bitte gib nicht mehr als ${OPTION_LIMIT} Antwortmöglichkeiten an!`;
else if (pollOptions.some(value => value.length > POLL_OPTION_MAX_LENGTH))

if (pollOptions.some(value => value.length > POLL_OPTION_MAX_LENGTH))
return `Bruder mindestens eine Antwortmöglichkeit ist länger als ${POLL_OPTION_MAX_LENGTH} Zeichen!`;

const fields = pollOptions.map((o, i) => createOptionField(o, i));
Expand Down Expand Up @@ -197,7 +200,9 @@ export const run: CommandFunction = async (_client, message, args, context) => {
if (options.delayed) {
if (Number.isNaN(delayTime) || delayTime <= 0) {
return "Bruder keine ungültigen Zeiten angeben 🙄";
} else if (delayTime > 60 * 1000 * 24 * 7) {
}

if (delayTime > 60 * 1000 * 24 * 7) {
return "Bruder du kannst maximal 7 Tage auf ein Ergebnis warten 🙄";
}

Expand Down Expand Up @@ -253,9 +258,8 @@ export const run: CommandFunction = async (_client, message, args, context) => {
reactionMap,
};

const additionalData = await AdditionalMessageData.fromMessage(
pollMessage,
);
const additionalData =
await AdditionalMessageData.fromMessage(pollMessage);
const newCustomData = additionalData.customData;
newCustomData.delayedPollData = delayedPollData;
additionalData.customData = newCustomData;
Expand Down Expand Up @@ -304,9 +308,8 @@ export const processPolls = async (context: BotContext) => {
) !== uidi,
)
.map(async uidToResolve => {
users[uidToResolve] = await context.client.users.fetch(
uidToResolve,
);
users[uidToResolve] =
await context.client.users.fetch(uidToResolve);
}),
);

Expand Down
14 changes: 5 additions & 9 deletions src/commands/roll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ const config = getConfig();
* @param {number} max
* @returns {number} A pseudo randomly generated number
*/
const pseudoRng = function (min: number, max: number): number {
return Math.floor(Math.random() * max + min);
};
const pseudoRng = (min: number, max: number): number =>
Math.floor(Math.random() * max + min);

/**
* Return an error string if an error exists.
Expand All @@ -23,10 +22,7 @@ const pseudoRng = function (min: number, max: number): number {
*
* @returns the error string
*/
const checkParams = function (
amount: number,
sides: number,
): string | undefined {
const checkParams = (amount: number, sides: number): string | undefined => {
if (!Number.isSafeInteger(amount) || !Number.isSafeInteger(sides)) {
return "Bruder nimm ma bitte nur natürliche Zahlen (>0).";
}
Expand Down Expand Up @@ -59,7 +55,7 @@ const checkParams = function (
*
* @returns diceResult of the thrown dice
*/
const diceResult = function (diceAmount: number, diceSides: number): number[] {
const diceResult = (diceAmount: number, diceSides: number): number[] => {
const res = [];
for (let i = 0; i < diceAmount; ++i) {
res.push(pseudoRng(1, diceSides));
Expand All @@ -75,7 +71,7 @@ const diceResult = function (diceAmount: number, diceSides: number): number[] {
*
* @returns {string} the constructed result
*/
const constructResultStr = function (rolls: readonly number[]): string {
const constructResultStr = (rolls: readonly number[]): string => {
let res = "";

for (let i = 0; i < rolls.length; ++i) {
Expand Down
5 changes: 2 additions & 3 deletions src/commands/special/wat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ export class WatCommand implements SpecialCommand {
const messageRef = message.reference?.messageId;
// If reply to message
if (messageRef) {
const quotedMessage = await message.channel.messages.fetch(
messageRef,
);
const quotedMessage =
await message.channel.messages.fetch(messageRef);
await quotedMessage.react(watEmote);
return;
}
Expand Down
Loading

0 comments on commit dbeb428

Please sign in to comment.