Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] /poll command #85

Draft
wants to merge 56 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
e3217fa
feat: start working on /poll
Sv443 Sep 5, 2022
b4b7c1d
pagarafe
Sv443 Sep 5, 2022
1dc0481
i am
Sv443 Sep 5, 2022
c8e23d3
feat: poll db stuff
Sv443 Sep 5, 2022
0855e41
refactor: better warning text
Sv443 Sep 5, 2022
a8e077c
feat: /poll list
Sv443 Sep 5, 2022
ce729bc
feat: more poll stoof
Sv443 Sep 5, 2022
7bdba0c
feat: more poll stuffs
Sv443 Sep 6, 2022
c4dc9fd
feat: more poll stuff
Sv443 Sep 6, 2022
8ca408e
lots of shit
Sv443 Sep 6, 2022
556425d
Merge branch 'main' into feat/poll
Sv443 Sep 7, 2022
33704ba
Merge branch 'main' into feat/poll
Sv443 Sep 13, 2022
4bc415e
feat: lots more poll stuff
Sv443 Sep 13, 2022
9e0d403
feat: unfinished poll stuff
Sv443 Sep 14, 2022
2d89dfd
hopefully fix: reminder double DM
Sv443 Sep 17, 2022
ce0f3ff
feat: private reminders
Sv443 Sep 23, 2022
f548674
fix: random stuff
Sv443 Sep 23, 2022
65549e3
fix: don't force DM if reminder not private
Sv443 Sep 24, 2022
bee9975
Merge branch 'main' into feat/poll
Sv443 Sep 24, 2022
708d169
chore: add license
Sv443 Sep 27, 2022
2b99046
fix: 1 sentence translation
Sv443 Sep 27, 2022
22ab6a8
feat: lots more unfinished /poll stuff
Sv443 Sep 27, 2022
d79412d
feat: poll
Sv443 Sep 27, 2022
b288634
fix: small type issues
Sv443 Sep 27, 2022
b90604e
feat: some util funcs
Sv443 Sep 27, 2022
e12b817
I will actually end someone
Sv443 Sep 30, 2022
9b3853f
fix: steam error logging cause i cant code for shit
Sv443 Sep 30, 2022
ba03b7f
fix: update api urls
Sv443 Oct 3, 2022
8dbae03
fix: reminder improvements
Sv443 Oct 3, 2022
3e7e0e2
fix: truncField error
Sv443 Oct 4, 2022
ae971c2
I am about to commit multiple counts of arson
Sv443 Oct 5, 2022
8f339d1
chore: update SCL
Sv443 Oct 11, 2022
a545cfb
Merge remote-tracking branch 'origin/main' into feat/poll
Sv443 Oct 11, 2022
632693c
chore: bump SCL
Sv443 Oct 11, 2022
3cb91e1
fix: random poll stuff
Sv443 Oct 11, 2022
b6d0b2d
fix: use redis instead of Set cause node hates it
Sv443 Oct 11, 2022
ed1f3a8
fix: timeouts of btnmsg and pageembed
Sv443 Oct 12, 2022
4a458f1
fix: when want GET HEAD
Sv443 Oct 13, 2022
665b321
still unfinished poll shit ngl
Sv443 Oct 20, 2022
629360a
Merge remote-tracking branch 'origin/main' into feat/poll
Sv443 Oct 20, 2022
1861000
fix: implement btnmsg tuple
Sv443 Oct 20, 2022
65718ed
fix: change casing of jobs
Sv443 Oct 22, 2022
fbf661c
ite
Sv443 Oct 22, 2022
ce0d5d8
refactor: sorry couldnt resist it
Sv443 Oct 22, 2022
382aa65
fix: refactor code & fix poll time parsing
Sv443 Nov 3, 2022
e02bbb1
fix: ci: remove node-canvas deps condition
Sv443 Nov 3, 2022
b8dc63e
just to be safe
Sv443 Nov 3, 2022
ed74eb2
refactor: unify emojis
Sv443 Nov 8, 2022
a766ef3
feat: fix poll time parsing
Sv443 Nov 8, 2022
6d357bb
ngl poll stuff
Sv443 Nov 16, 2022
d6eea70
stuff n shid
Sv443 Nov 16, 2022
82ad79e
feat: command prefix env var
Sv443 Nov 20, 2022
19095f2
fix: remove underscore in cmd prefix
Sv443 Nov 20, 2022
abe9ca3
this shit aint working
Sv443 Nov 20, 2022
0d2f47f
chore: unhide some excluded files
Sv443 Dec 4, 2022
71cb90f
feat: input lang & more improvements in /translate
Sv443 Dec 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ SPOTIFY_CLIENT_ID=123123123 # https://developer.spotify.com/dashboard/
SPOTIFY_CLIENT_SECRET=123123123

# Settings
COMMAND_PREFIX="" # Set to something like an abbreviation of the client's name so all commands have that prefix and can be distinguished better - empty for none
DEV_IDS="123,456" # All user IDs that should have dev perms
BELL_ON_READY=false # Set to true to send a console bell sound when the client is ready
EXEC_CMD_ENABLED=true # Set to false to disable the /exec command
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ jobs:
- name: Install node-canvas dependencies
run: |
sudo apt update
sudo apt install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev
if: matrix.node-version == '18.x'
sudo apt install -y build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev

- name: Install npm dependencies
run: |
npm install -g tsc
npm install
npm i -g tsc
npm ci

- run: npm run lint
- name: Run ESLint
run: npm run lint


2 changes: 0 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@
"editor.defaultFormatter": "vscode.json-language-features",
},
"files.exclude": {
"**/.env": true,
"out/**": true,
"node_modules/": true
},
"git.branchPrefix": "feat/",
"git.branchProtection": [ "main" ],
Expand Down
661 changes: 661 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

79 changes: 38 additions & 41 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"type": "git",
"url": "git+https://github.com/codedrunks/BrewBot.git"
},
"license": "UNLICENSED",
"license": "AGPL-3.0",
"bugs": {
"url": "https://github.com/codedrunks/BrewBot/issues"
},
Expand Down Expand Up @@ -58,7 +58,7 @@
"redis": "^4.2.0",
"simple-statistics": "^7.7.5",
"steamapi": "^2.2.0",
"svcorelib": "^1.16.0",
"svcorelib": "^1.18.1",
"yargs": "^17.5.1"
},
"bin": {
Expand Down
22 changes: 20 additions & 2 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ model Reminder {
dueTimestamp DateTime
guild String?
channel String?
private Boolean @default(false)
User User @relation(fields: [userId], references: [id], onDelete: Cascade)

@@id([reminderId, userId])
Expand Down Expand Up @@ -82,6 +83,7 @@ model Guild {
premium Boolean? @default(false)
lastLogColor String?
contests Contest[]
polls Poll[]
GuildSettings GuildSettings?
}

Expand All @@ -97,6 +99,22 @@ model GuildSettings {
Guild Guild @relation(fields: [guildId], references: [id], onDelete: Cascade)
}

model Poll {
pollId Int
guildId String
channel String
messages String[]
createdBy String
headline String?
topic String?
voteOptions String[]
votesPerUser Int
dueTimestamp DateTime
Guild Guild @relation(fields: [guildId], references: [id])

@@id([pollId, guildId])
}

//#MARKER contest
model Contest {
id Int
Expand Down Expand Up @@ -136,8 +154,8 @@ model SubmissionVote {
model TwentyFortyEightLeaderboardEntry {
guildId String
userId String
score Int @default(0)
gamesWon Int @default(0)
score Int @default(0)
gamesWon Int @default(0)
member Member @relation(fields: [guildId, userId], references: [guildId, userId])

@@id([guildId, userId])
Expand Down
18 changes: 12 additions & 6 deletions src/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export abstract class Command
this.meta = { ...fallbackMeta, ...cmdMeta };
const { name, desc, args } = this.meta;

data.setName(name)
data.setName(this.getFullCmdName(name))
.setDescription(desc);

Array.isArray(args) && args.forEach(arg => {
Expand Down Expand Up @@ -96,7 +96,7 @@ export abstract class Command
opt.setName(arg.name)
.setDescription(arg.desc)
.setRequired(arg.required ?? false)
.addChannelTypes(ChannelType.GuildText, ChannelType.GuildNews, ChannelType.GuildPublicThread)
.addChannelTypes(ChannelType.GuildText, ChannelType.GuildNews, ChannelType.GuildPublicThread, ChannelType.GuildPrivateThread, ChannelType.GuildVoice)
);
else if(arg.type === ApplicationCommandOptionType.Role)
data.addRoleOption(opt =>
Expand All @@ -121,15 +121,15 @@ export abstract class Command
return opt;
});
else
throw new Error("Unimplemented option type");
throw new Error(`Unimplemented argument type in /${cmdMeta.name}`);
});
}
else
{
// subcommands
this.meta = { ...fallbackMeta, ...cmdMeta };

data.setName(cmdMeta.name)
data.setName(this.getFullCmdName(cmdMeta.name))
.setDescription(cmdMeta.desc);

cmdMeta.subcommands.forEach(scmd => {
Expand Down Expand Up @@ -187,7 +187,7 @@ export abstract class Command
opt.setName(arg.name)
.setDescription(arg.desc)
.setRequired(arg.required ?? false)
.addChannelTypes(ChannelType.GuildText, ChannelType.GuildNews, ChannelType.GuildPublicThread)
.addChannelTypes(ChannelType.GuildText, ChannelType.GuildNews, ChannelType.GuildPublicThread, ChannelType.GuildPrivateThread, ChannelType.GuildVoice)
);
else if(arg.type === ApplicationCommandOptionType.Role)
sc.addRoleOption(opt =>
Expand All @@ -212,7 +212,7 @@ export abstract class Command
return opt;
});
else
throw new Error("Unimplemented option");
throw new Error(`Unimplemented argument type in /${cmdMeta.name} ${scmd.name}`);
});

return sc;
Expand All @@ -226,6 +226,12 @@ export abstract class Command

//#SECTION public

/** Returns the full name of the given command name, including optional prefix */
public getFullCmdName(cmdName: string)
{
return `${settings.client.commandPrefix ?? ""}${cmdName}`;
}

/** Called when a user tries to run this command (if the user doesn't have perms this resolves null) */
public async tryRun(int: CommandInteraction, opt?: CommandInteractionOption<"cached">): Promise<unknown>
{
Expand Down
2 changes: 1 addition & 1 deletion src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ async function registerCommands(client: Client)

const opts = options.data && options.data.length > 0 ? options.data : undefined;

const cmd = cmds.find(({ meta }) => meta.name === commandName);
const cmd = cmds.find((cmd) => cmd.getFullCmdName(cmd.meta.name) === commandName);

if(!cmd || !cmd.enabled)
return;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/economy/Job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Command } from "@src/Command";
import { getTotalWorks } from "@database/economy";
import { settings } from "@src/settings";
import { embedify } from "@utils/embedify";
import { Levels, totalWorksToLevel, baseAward } from "@commands/economy/Jobs";
import { jobLevels, totalWorksToLevel, baseAward } from "@src/commands/economy/jobs";

export class Job extends Command {
constructor() {
Expand All @@ -26,7 +26,7 @@ export class Job extends Command {
if(!totalworks || totalworks == 0) return this.reply(int, embedify("We have no job records for you, ya bum! Consider doing something using `/work`"), true);

const jobidx = totalWorksToLevel(totalworks);
const job = Levels[jobidx as keyof typeof Levels];
const job = jobLevels[jobidx as keyof typeof jobLevels];

const { name, multiplier } = job;

Expand Down
6 changes: 3 additions & 3 deletions src/commands/economy/Work.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Command } from "@src/Command";
import { embedify, formatSeconds, nowInSeconds } from "@utils/index";
import { addCoins, getLastWork, getTotalWorks, incrementTotalWorks, setLastWork } from "@database/economy";
import { createNewMember, getMember } from "@database/users";
import { Levels, totalWorksToLevel, baseAward } from "@commands/economy/Jobs";
import { jobLevels, totalWorksToLevel, baseAward } from "@src/commands/economy/jobs";
import { randomItem } from "svcorelib";

const secs4hours = 14400;
Expand Down Expand Up @@ -41,7 +41,7 @@ export class Work extends Command {
await setLastWork(userid, guildid);

const jobidx = totalWorksToLevel(totalworks);
const job = Levels[jobidx as keyof typeof Levels];
const job = jobLevels[jobidx as keyof typeof jobLevels];

const payout = Math.round(job.multiplier * baseAward);

Expand All @@ -60,7 +60,7 @@ export class Work extends Command {
await setLastWork(userid, guildid);

const jobidx = totalWorksToLevel(totalworks);
const job = Levels[jobidx as keyof typeof Levels];
const job = jobLevels[jobidx as keyof typeof jobLevels];

const payout = Math.round(job.multiplier * baseAward);

Expand Down
1 change: 1 addition & 0 deletions src/commands/economy/jobs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./jobs";
Loading