Skip to content
This repository was archived by the owner on Sep 1, 2023. It is now read-only.

Commit 810faee

Browse files
committed
Initial commit
0 parents  commit 810faee

18 files changed

+887
-0
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
indent_style = space
8+
indent_size = 4
9+
end_of_line = lf
10+
charset = utf-8
11+
trim_trailing_whitespace = true
12+
insert_final_newline = true

.env.example

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TOKEN=amogus

.eslintrc.json

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"ignorePatterns": ["dist"],
5+
"plugins": ["@typescript-eslint", "unused-imports"],
6+
"rules": {
7+
"quotes": ["error", "double", { "avoidEscape": true }],
8+
"jsx-quotes": ["error", "prefer-double"],
9+
"no-mixed-spaces-and-tabs": "error",
10+
"indent": ["error", 4, { "SwitchCase": 1 }],
11+
"arrow-parens": ["error", "as-needed"],
12+
"eol-last": ["error", "always"],
13+
"func-call-spacing": ["error", "never"],
14+
"no-multi-spaces": "error",
15+
"no-trailing-spaces": "error",
16+
"no-whitespace-before-property": "error",
17+
"semi": ["error", "never"],
18+
"space-in-parens": ["error", "never"],
19+
"block-spacing": ["error", "always"],
20+
"object-curly-spacing": ["error", "always"],
21+
"eqeqeq": ["error", "always", { "null": "ignore" }],
22+
"spaced-comment": ["error", "always", { "markers": ["!"] }],
23+
"yoda": "error",
24+
"prefer-destructuring": ["error", { "object": true, "array": false }],
25+
"operator-assignment": ["error", "always"],
26+
"no-useless-computed-key": "error",
27+
"no-unneeded-ternary": ["error", { "defaultAssignment": false }],
28+
"no-invalid-regexp": "error",
29+
"no-constant-condition": ["error", { "checkLoops": false }],
30+
"no-duplicate-imports": "error",
31+
"no-extra-semi": "error",
32+
"dot-notation": "error",
33+
"no-useless-escape": "error",
34+
"no-fallthrough": "error",
35+
"for-direction": "error",
36+
"no-async-promise-executor": "error",
37+
"no-cond-assign": "error",
38+
"no-dupe-else-if": "error",
39+
"no-duplicate-case": "error",
40+
"no-irregular-whitespace": "error",
41+
"no-loss-of-precision": "error",
42+
"no-misleading-character-class": "error",
43+
"no-prototype-builtins": "error",
44+
"no-regex-spaces": "error",
45+
"no-shadow-restricted-names": "error",
46+
"no-unexpected-multiline": "error",
47+
"no-unsafe-optional-chaining": "error",
48+
"no-useless-backreference": "error",
49+
"use-isnan": "error",
50+
"prefer-const": "error",
51+
"prefer-spread": "error",
52+
53+
"unused-imports/no-unused-imports": "error"
54+
}
55+
}

.gitignore

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
.pnpm-debug.log*
9+
10+
# Diagnostic reports (https://nodejs.org/api/report.html)
11+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
*.lcov
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Dependency directories
42+
node_modules/
43+
jspm_packages/
44+
45+
# Snowpack dependency directory (https://snowpack.dev/)
46+
web_modules/
47+
48+
# TypeScript cache
49+
*.tsbuildinfo
50+
51+
# Optional npm cache directory
52+
.npm
53+
54+
# Optional eslint cache
55+
.eslintcache
56+
57+
# Optional stylelint cache
58+
.stylelintcache
59+
60+
# Microbundle cache
61+
.rpt2_cache/
62+
.rts2_cache_cjs/
63+
.rts2_cache_es/
64+
.rts2_cache_umd/
65+
66+
# Optional REPL history
67+
.node_repl_history
68+
69+
# Output of 'npm pack'
70+
*.tgz
71+
72+
# Yarn Integrity file
73+
.yarn-integrity
74+
75+
# dotenv environment variable files
76+
.env
77+
.env.development.local
78+
.env.test.local
79+
.env.production.local
80+
.env.local
81+
82+
# parcel-bundler cache (https://parceljs.org/)
83+
.cache
84+
.parcel-cache
85+
86+
# Next.js build output
87+
.next
88+
out
89+
90+
# Nuxt.js build / generate output
91+
.nuxt
92+
dist
93+
94+
# Gatsby files
95+
.cache/
96+
# Comment in the public line in if your project uses Gatsby and not Next.js
97+
# https://nextjs.org/blog/next-9-1#public-directory-support
98+
# public
99+
100+
# vuepress build output
101+
.vuepress/dist
102+
103+
# vuepress v2.x temp and cache directory
104+
.temp
105+
.cache
106+
107+
# Docusaurus cache and generated files
108+
.docusaurus
109+
110+
# Serverless directories
111+
.serverless/
112+
113+
# FuseBox cache
114+
.fusebox/
115+
116+
# DynamoDB Local files
117+
.dynamodb/
118+
119+
# TernJS port file
120+
.tern-port
121+
122+
# Stores VSCode versions used for testing VSCode extensions
123+
.vscode-test
124+
125+
# yarn v2
126+
.yarn/cache
127+
.yarn/unplugged
128+
.yarn/build-state.yml
129+
.yarn/install-state.gz
130+
.pnp.*
131+
132+
pnpm-lock.yaml
133+
_commandTemplate.ts

.vscode/settings.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"editor.codeActionsOnSave": {
4+
"source.fixAll.eslint": true
5+
},
6+
"[typescript]": {
7+
"editor.defaultFormatter": "vscode.typescript-language-features"
8+
},
9+
"tsimporter.emitSemicolon": true
10+
}

package.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "buno",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"build:start": "npx tsc && node dist/.",
9+
"build": "npx tsc",
10+
"start": "node dist/."
11+
},
12+
"keywords": [],
13+
"author": "",
14+
"license": "ISC",
15+
"dependencies": {
16+
"@oceanicjs/builders": "^1.1.7",
17+
"dotenv": "^16.0.3",
18+
"oceanic.js": "^1.5.0"
19+
},
20+
"devDependencies": {
21+
"@typescript-eslint/eslint-plugin": "^5.53.0",
22+
"@typescript-eslint/parser": "^5.53.0",
23+
"eslint": "^8.34.0",
24+
"eslint-plugin-unused-imports": "^2.0.0",
25+
"typescript": "^4.9.5"
26+
},
27+
"type": "module"
28+
}

src/client.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { config } from "dotenv"; config()
2+
import { Client, CreateMessageOptions, Message } from "oceanic.js"
3+
4+
export const client = new Client({
5+
auth: `Bot ${process.env.TOKEN}`,
6+
gateway: {
7+
intents: ["GUILDS", "GUILD_MESSAGES", "MESSAGE_CONTENT"]
8+
},
9+
allowedMentions: { roles: false }
10+
})
11+
12+
export const sendMessage = (channelId: string, content: CreateMessageOptions | string) =>
13+
client.rest.channels.createMessage(channelId, typeof content === "string" ? { content } : content)
14+
export function editMessage(message: Message, content: CreateMessageOptions | string): any {
15+
return client.rest.channels.editMessage(message.channelID, message.id, typeof content === "string" ? { content } : content)
16+
}
17+
export const deleteMessage = (message: Message) => client.rest.channels.deleteMessage(message.channel.id, message.id)
18+
export const respond = (msg: Message, c: CreateMessageOptions | string) => {
19+
let content: CreateMessageOptions = { messageReference: { messageID: msg.id, channelID: msg.channel.id } }
20+
if (typeof c === "string") content.content = c
21+
else content = { ...content, ...c }
22+
sendMessage(msg.channelID, content)
23+
}

src/commands/eval.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Command } from "../types"
2+
import { inspect } from "util"
3+
import { respond } from "../client.js"
4+
5+
const DEV_IDS = ["406028027768733696"]
6+
const MAX_RESPONSE_LENGTH = 1950
7+
8+
export const cmd = {
9+
name: "eval",
10+
execute: (msg, args) => {
11+
if (!DEV_IDS.includes(msg.author.id)) return
12+
const code = args.join(" ")
13+
const reportError = (e: Error): void => {
14+
respond(msg, `Error\n\`\`\`ts\n${e}\`\`\``)
15+
console.log(e)
16+
}
17+
msg.createReaction("👍")
18+
try {
19+
(eval(`(async function(){${code}})().catch(reportError)`) as Promise<any>).then(evalResult => {
20+
let result = inspect(evalResult, { depth: 5 })
21+
if (result.length > MAX_RESPONSE_LENGTH)
22+
for (let i = 4; i > 0; i--) {
23+
if (result.length > MAX_RESPONSE_LENGTH) result = inspect(evalResult, { depth: i })
24+
}
25+
if (result.length > MAX_RESPONSE_LENGTH) {
26+
result = "Too long, sending to console"
27+
console.log(inspect(evalResult, { depth: 4, colors: true }))
28+
}
29+
if (result !== "undefined") respond(msg, "```ts\n" + result + "```")
30+
}).catch(reportError)
31+
} catch (e) { reportError(e) }
32+
},
33+
} as Command

src/commands/test.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { sendMessage } from "../client.js"
2+
import { Command } from "../types"
3+
4+
export const cmd = {
5+
name: "test",
6+
execute: (msg, args) => {
7+
sendMessage(msg.channelID, {
8+
content: "it's alive!!"
9+
})
10+
},
11+
} as Command

src/commands/uno.ts

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { respond } from "../client.js"
2+
import { Command, UnoGame } from "../types"
3+
import { ComponentBuilder } from "@oceanicjs/builders"
4+
import { ButtonStyles, MessageActionRow } from "oceanic.js"
5+
import { games, makeStartMessage } from "../gameLogic/index.js"
6+
import { ButtonIDs } from "../constants.js"
7+
8+
export const cmd = {
9+
name: "uno",
10+
execute: (msg, args) => {
11+
if (games[msg.channelID]) return respond(msg, "someone already started a game")
12+
const gameObj: UnoGame<false> = {
13+
started: false,
14+
host: msg.author.id,
15+
message: msg,
16+
players: [msg.author.id],
17+
}
18+
respond(msg, {
19+
embeds: [makeStartMessage(gameObj)],
20+
components: new ComponentBuilder<MessageActionRow>()
21+
.addInteractionButton({
22+
style: ButtonStyles.PRIMARY,
23+
customID: ButtonIDs.JOIN_GAME,
24+
label: "Join",
25+
})
26+
.addInteractionButton({
27+
style: ButtonStyles.DANGER,
28+
customID: ButtonIDs.LEAVE_GAME_BEFORE_START,
29+
emoji: ComponentBuilder.emojiToPartial("🛑", "default")
30+
})
31+
.addInteractionButton({
32+
style: ButtonStyles.PRIMARY,
33+
customID: ButtonIDs.START_GAME,
34+
emoji: ComponentBuilder.emojiToPartial("▶", "default")
35+
})
36+
.addRow()
37+
.addInteractionButton({
38+
style: ButtonStyles.SECONDARY,
39+
customID: ButtonIDs.EDIT_GAME_SETTINGS,
40+
label: "Settings (host only)",
41+
emoji: ComponentBuilder.emojiToPartial("⚙", "default")
42+
})
43+
.toJSON()
44+
})
45+
games[msg.channelID] = gameObj
46+
},
47+
} as Command

0 commit comments

Comments
 (0)