Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eabe9c9f95 | ||
|
|
94650da46e | ||
|
|
e22045b69a | ||
|
|
911ad50602 | ||
|
|
918e498ac3 | ||
|
|
8ec2b4dca2 | ||
|
|
d0ed5f7e00 | ||
|
|
7e3e7ecbf8 | ||
|
|
efaee7d035 | ||
|
|
e1c499328a | ||
|
|
f7ba8187fe | ||
|
|
be4106b262 | ||
|
|
9364c1767a | ||
|
|
089e13b9ff | ||
|
|
ffc034dbdd | ||
|
|
a2c8e1cfee | ||
|
|
f308503816 | ||
|
|
4f11342db8 | ||
|
|
4af3c0adfa | ||
|
|
f2371974cd | ||
|
|
5d5efa884d | ||
|
|
8a3f9bb03c | ||
|
|
60bf216d71 | ||
|
|
cee3c07409 | ||
|
|
481a1f3f25 |
20
.github/workflows/deploy.yaml
vendored
Normal file
20
.github/workflows/deploy.yaml
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
name: Deploy
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: ["canary"]
|
||||||
|
pull_request:
|
||||||
|
branches: ["main"]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: self-hosted
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Build image
|
||||||
|
run: docker build -t ${{ github.repository }} .
|
||||||
|
- name: Deploy image
|
||||||
|
run: |
|
||||||
|
docker stop ${{ github.event.repository.name }} || true
|
||||||
|
docker rm ${{ github.event.repository.name }} || true
|
||||||
|
docker run -d -e "DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }}" -e "REDIS_TOKEN=${{ secrets.REDIS_TOKEN }}" -e "DATABASE_URL=${{ secrets.DATABASE_URL }}" --restart always --network BOT --name ${{ github.event.repository.name }} ${{ github.repository }}
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
/node_modules
|
/node_modules
|
||||||
.env
|
.env
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
/src/badges
|
||||||
10
Dockerfile
Normal file
10
Dockerfile
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# syntax=docker/dockerfile:1
|
||||||
|
FROM node:16.10.0
|
||||||
|
WORKDIR /app
|
||||||
|
COPY ./ ./
|
||||||
|
RUN apt-get -y update
|
||||||
|
RUN apt-get install -y build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev
|
||||||
|
RUN npm install --build-from-source canvas
|
||||||
|
RUN npm install
|
||||||
|
CMD ["npx", "prisma", "db", "push"]
|
||||||
|
CMD ["node", "index.js"]
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
# gractwo-bot
|
# gractwo-bot
|
||||||
gractwo-bot is a Discord bot written in JavaScript, using node.js and discord.js.
|
|
||||||
|
<b>gractwo-bot</b> is a Discord bot written in JavaScript, using node.js and discord.js.
|
||||||
It has been created for and only serves the Gractwo Discord server. It is hosted using Heroku.
|
It has been created for and only serves the Gractwo Discord server. It is hosted using Heroku.
|
||||||
|
|||||||
95
cfg.json
Normal file
95
cfg.json
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
{
|
||||||
|
"prefix": "&",
|
||||||
|
"hexBlue": "61f2ea",
|
||||||
|
"hexRed": "fb636b",
|
||||||
|
"iconurl": "https://i.imgur.com/4AmRDyX.png",
|
||||||
|
"timeout": 4000,
|
||||||
|
"rolesList": [
|
||||||
|
"tf2",
|
||||||
|
"liga",
|
||||||
|
"csgo",
|
||||||
|
"minecraft",
|
||||||
|
"rainbow-six",
|
||||||
|
"apex",
|
||||||
|
"genshin",
|
||||||
|
"valorant"
|
||||||
|
],
|
||||||
|
"embedFields": {
|
||||||
|
"witaj": [
|
||||||
|
{
|
||||||
|
"name": "Zasady",
|
||||||
|
"value": "Zasady serwera są spisane na kanale `regulamin`. Pamiętajcie, by tam zajrzeć."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Gractwo WWW",
|
||||||
|
"value": "http://gractwo.pl",
|
||||||
|
"inline": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Gractwo DISCORD",
|
||||||
|
"value": "http://gractwo.pl/discord",
|
||||||
|
"inline": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "DISCORD bezpośredni",
|
||||||
|
"value": "discord.gg/NBXq95C",
|
||||||
|
"inline": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Gractwo TWITTER",
|
||||||
|
"value": "http://gractwo.pl/twitter",
|
||||||
|
"inline": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Gractwo YOUTUBE",
|
||||||
|
"value": "http://gractwo.pl/youtube",
|
||||||
|
"inline": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Gractwo GITHUB",
|
||||||
|
"value": "http://gractwo.pl/github",
|
||||||
|
"inline": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"regulamin": [
|
||||||
|
{
|
||||||
|
"name": "§1 Szacunek",
|
||||||
|
"value": "Na naszym serwerze obowiązuje szacunek do innych osób podczas niesatyrycznej dyskusji."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "§2 Spam / Trolling",
|
||||||
|
"value": "Jeżeli będziesz bezużytecznie spamować lub nieprzyjmenie się zachowywać zostaniesz zbanowany."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "§3 Bagno",
|
||||||
|
"value": "Kanał #bagno jest najbardziej wyluzowanym kanałem na naszym serwerze. Nie oznacza to jednak, że nie jest monitorowany. Jeżeli czujesz, że rzecz którą chcesz tam umieścić jest nadzwyczajnie kontrowersyjna, zastanów się dwa razy przed wciśnięciem Enter."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "§4 Poprawne Kanały",
|
||||||
|
"value": "Rozmowy na dany temat powinny toczyć się w kanałach do tego przeznaczonych."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "§5 Memy i Gify",
|
||||||
|
"value": "Memy i Gify nie są zbyt przyjemne dla oka bez kontekstu. Najlepiej jest nie postować ich, jeżeli nie pasują do prowadzonej aktualnie dyskusji."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "§6 Reklamy",
|
||||||
|
"value": "Zakaz reklam bez zezwolenia moderatora lub administratora. Pozwolenia na reklamę muszą być wydane przed jej zamieszczeniem."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "§7 Przestrzeganie Regulaminu",
|
||||||
|
"value": "Przestrzeganie regulaminu jest obowiązkowe, a to że go ktoś nie przeczytał nic nie zmienia."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "§8 Obcowanie z botem",
|
||||||
|
"value": "Próby intencjonalnego łamania bota nie są mile widziane, tak jak nadużywanie go w celach spamu kanałów."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "§9 Warunki Użytkowania Discord (ToS)",
|
||||||
|
"value": "Nasz serwer, jak każdy inny, musi przestrzegać zasad zapisanych w warunkach użytkowania Discorda. Przypominamy o nich, bo choć nie są zbyt restrykcyjne, nie pozwalają na kilka określonych rzeczy."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"pomocDesc": "Komenda objaśniająca bota i jego zastosowanie, a także dostępne komendy.\n\nBot Gractwa funkcjonuje jako własne rozwiązanie na problemy z administrowaniem serwera Discord. Umożliwia między innymi samo-nadawanie rolek od gier, lub odsłuchiwanie muzyki.\n\nPoniżej znajduje się lista dostępnych komend:",
|
||||||
|
"rolkiDesc": "Poniżej widnieją przyciski służące do przyznawania bądź odejmowanie sobie ról powiązanych z grami. Służą one do oznaczania wszystkich zainteresowanych daną grą na określonym kanale."
|
||||||
|
}
|
||||||
|
}
|
||||||
95
index.js
Normal file
95
index.js
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
const discordjs = require("discord.js");
|
||||||
|
const fs = require("fs");
|
||||||
|
const redis = require("./src/functions/redis");
|
||||||
|
const { Postgres } = require("./src/functions/postgres");
|
||||||
|
const { createClient } = require("redis");
|
||||||
|
const colors = require("colors");
|
||||||
|
|
||||||
|
colors.setTheme({
|
||||||
|
prompt: "grey",
|
||||||
|
info: "green",
|
||||||
|
warn: "yellow",
|
||||||
|
debug: "blue",
|
||||||
|
error: "red",
|
||||||
|
});
|
||||||
|
|
||||||
|
require("dotenv").config();
|
||||||
|
|
||||||
|
const cl = new discordjs.Client({
|
||||||
|
intents: [
|
||||||
|
discordjs.Intents.FLAGS.GUILDS,
|
||||||
|
discordjs.Intents.FLAGS.GUILD_MESSAGES,
|
||||||
|
discordjs.Intents.FLAGS.GUILD_VOICE_STATES,
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
//redis connect
|
||||||
|
const redisConnection = createClient({
|
||||||
|
url: process.env.REDIS_TOKEN,
|
||||||
|
});
|
||||||
|
redisConnection
|
||||||
|
.connect()
|
||||||
|
.then(() => console.log("✔️ redis connected".info))
|
||||||
|
.catch((err) => console.error(err.stack.red));
|
||||||
|
|
||||||
|
//postgres connection
|
||||||
|
const client = new Postgres();
|
||||||
|
|
||||||
|
cl.cfg = require("./cfg.json");
|
||||||
|
cl.cmds = new discordjs.Collection();
|
||||||
|
|
||||||
|
//cmds handler
|
||||||
|
const cmdsFls = fs
|
||||||
|
.readdirSync(`./src/cmds`)
|
||||||
|
.filter((file) => file.endsWith(`.js`));
|
||||||
|
for (const Fl of cmdsFls) {
|
||||||
|
const cmd = require(`./src/cmds/${Fl}`);
|
||||||
|
console.log(`command: ` + cmd.name);
|
||||||
|
cl.cmds.set(cmd.name, cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
//command execution
|
||||||
|
cl.on("messageCreate", async (msg) => {
|
||||||
|
if (msg.author.bot) return;
|
||||||
|
|
||||||
|
//exp
|
||||||
|
if (!msg.content.startsWith(cl.cfg.prefix)) {
|
||||||
|
client.messageCount(msg.author.id, msg.channel.id);
|
||||||
|
if (await redis.expCheck(msg.author.id, redisConnection)) {
|
||||||
|
client.addExp(msg.author.id, 10, 25);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//client.messageCount(msg.author.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const args = msg.content.slice(cl.cfg.prefix.length).trim().split(/ +/);
|
||||||
|
const cmdName = args.shift().toLowerCase();
|
||||||
|
|
||||||
|
if (!cl.cmds.has(cmdName)) return;
|
||||||
|
const cmd = cl.cmds.get(cmdName);
|
||||||
|
|
||||||
|
try {
|
||||||
|
cmd.execute(cl, msg, args, client);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(
|
||||||
|
`msgCommand error: ${cmdName} with args ${args} by ${msg.author.tag}\n--\n${error}\n--`
|
||||||
|
);
|
||||||
|
msg.reply(
|
||||||
|
`An error occured while trying to execute ${cmdName} with args ${args}`
|
||||||
|
);
|
||||||
|
console.log(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log(`msgCommand: ${cmdName + args} by ${msg.author.tag}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
//client
|
||||||
|
cl.once("ready", () => {
|
||||||
|
console.log(`bot ready; logged in as ${cl.user.tag}\n--`.info);
|
||||||
|
cl.user.setActivity(".pomoc", { type: "LISTENING" });
|
||||||
|
});
|
||||||
|
cl.login(process.env.TOKEN); // here comes the boooy
|
||||||
|
// hello boy
|
||||||
|
// welcome
|
||||||
|
// there he is
|
||||||
|
// he is here
|
||||||
5283
package-lock.json
generated
5283
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
57
package.json
57
package.json
@@ -1,28 +1,33 @@
|
|||||||
{
|
{
|
||||||
"name": "discord-bot",
|
"name": "discord-bot",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "gractwo-bot is a Discord bot written in JavaScript, using node.js and discord.js.\r It has been created for and only serves the Gractwo Discord server. It is hosted using Heroku.",
|
"description": "gractwo-bot is a Discord bot written in JavaScript, using node.js and discord.js.\r It has been created for and only serves the Gractwo Discord server. It is hosted using Heroku.",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"start": "nodemon"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/Gractwo/discord-bot.git"
|
"url": "git+https://github.com/Gractwo/discord-bot.git"
|
||||||
},
|
},
|
||||||
"author": "github.com/jakubmanczak",
|
"author": "github.com/jakubmanczak",
|
||||||
"license": "UNLICENSED",
|
"license": "UNLICENSED",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/Gractwo/discord-bot/issues"
|
"url": "https://github.com/Gractwo/discord-bot/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/Gractwo/discord-bot#readme",
|
"homepage": "https://github.com/Gractwo/discord-bot#readme",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.10.0",
|
"node": ">=16.10.0",
|
||||||
"npm": ">=7.24.0"
|
"npm": ">=7.24.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"discord.js": "^13.1.0",
|
"@prisma/client": "^3.12.0",
|
||||||
"dotenv": "^10.0.0",
|
"colors": "^1.4.0",
|
||||||
"nodemon": "^2.0.13"
|
"daemon": "^1.1.0",
|
||||||
}
|
"discord.js": "^13.6.0",
|
||||||
|
"dotenv": "^10.0.0",
|
||||||
|
"nodemon": "^2.0.16",
|
||||||
|
"prisma": "^3.13.0",
|
||||||
|
"redis": "^4.0.4"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
48
prisma/schema.prisma
Normal file
48
prisma/schema.prisma
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
generator client {
|
||||||
|
provider = "prisma-client-js"
|
||||||
|
binaryTargets = ["linux-musl"]
|
||||||
|
}
|
||||||
|
|
||||||
|
datasource db {
|
||||||
|
provider = "postgresql"
|
||||||
|
url = env("DATABASE_URL")
|
||||||
|
}
|
||||||
|
|
||||||
|
model badges {
|
||||||
|
badge_id Int @id
|
||||||
|
badge_name String
|
||||||
|
badge_description String
|
||||||
|
badge_visibility Boolean @default(true)
|
||||||
|
badge_type Int @default(0)
|
||||||
|
givenbadges givenbadges[]
|
||||||
|
}
|
||||||
|
|
||||||
|
model givenbadges {
|
||||||
|
user_id String
|
||||||
|
badge_id Int
|
||||||
|
date_of_confer DateTime @id @db.Date
|
||||||
|
badges badges @relation(fields: [badge_id], references: [badge_id], onDelete: NoAction, onUpdate: NoAction, map: "badge_id")
|
||||||
|
users users @relation(fields: [user_id], references: [user_id], onDelete: NoAction, onUpdate: NoAction, map: "user_id")
|
||||||
|
|
||||||
|
@@index([badge_id], map: "fki_badge_id")
|
||||||
|
@@index([user_id], map: "fki_user_id")
|
||||||
|
}
|
||||||
|
|
||||||
|
model users {
|
||||||
|
user_id String @id(map: "user_pkey")
|
||||||
|
exp Int @default(0)
|
||||||
|
voice_time Int @default(0)
|
||||||
|
lvl Int @default(0)
|
||||||
|
givenbadges givenbadges[]
|
||||||
|
sendmessages sendmessages[]
|
||||||
|
}
|
||||||
|
|
||||||
|
model sendmessages {
|
||||||
|
id Int @id @default(autoincrement())
|
||||||
|
user_id String
|
||||||
|
date DateTime @db.Date
|
||||||
|
channel String
|
||||||
|
msg_count Int
|
||||||
|
users users @relation(fields: [user_id], references: [user_id], onDelete: NoAction, onUpdate: NoAction, map: "user_id")
|
||||||
|
|
||||||
|
}
|
||||||
95
src/cfg.json
95
src/cfg.json
@@ -1,95 +0,0 @@
|
|||||||
{
|
|
||||||
"prefix": ".",
|
|
||||||
"hexBlue": "61f2ea",
|
|
||||||
"hexRed": "fb636b",
|
|
||||||
"iconurl": "https://i.imgur.com/4AmRDyX.png",
|
|
||||||
"timeout": 4000,
|
|
||||||
"rolesList": [
|
|
||||||
"tf2",
|
|
||||||
"liga",
|
|
||||||
"csgo",
|
|
||||||
"minecraft",
|
|
||||||
"rainbow-six",
|
|
||||||
"apex",
|
|
||||||
"genshin",
|
|
||||||
"valorant"
|
|
||||||
],
|
|
||||||
"embedFields": {
|
|
||||||
"witaj": [
|
|
||||||
{
|
|
||||||
"name": "Zasady",
|
|
||||||
"value": "Zasady serwera są spisane na kanale `regulamin`. Pamiętajcie, by tam zajrzeć."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Gractwo WWW",
|
|
||||||
"value": "http://gractwo.pl",
|
|
||||||
"inline": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Gractwo DISCORD",
|
|
||||||
"value": "http://gractwo.pl/discord",
|
|
||||||
"inline": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "DISCORD bezpośredni",
|
|
||||||
"value": "discord.gg/NBXq95C",
|
|
||||||
"inline": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Gractwo TWITTER",
|
|
||||||
"value": "http://gractwo.pl/twitter",
|
|
||||||
"inline": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Gractwo YOUTUBE",
|
|
||||||
"value": "http://gractwo.pl/youtube",
|
|
||||||
"inline": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Gractwo GITHUB",
|
|
||||||
"value": "http://gractwo.pl/github",
|
|
||||||
"inline": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"regulamin": [
|
|
||||||
{
|
|
||||||
"name": "§1 Szacunek",
|
|
||||||
"value": "Na naszym serwerze obowiązuje szacunek do innych osób podczas niesatyrycznej dyskusji."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "§2 Spam / Trolling",
|
|
||||||
"value": "Jeżeli będziesz bezużytecznie spamować lub nieprzyjmenie się zachowywać zostaniesz zbanowany."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "§3 Bagno",
|
|
||||||
"value": "Kanał #bagno jest najbardziej wyluzowanym kanałem na naszym serwerze. Nie oznacza to jednak, że nie jest monitorowany. Jeżeli czujesz, że rzecz którą chcesz tam umieścić jest nadzwyczajnie kontrowersyjna, zastanów się dwa razy przed wciśnięciem Enter."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "§4 Poprawne Kanały",
|
|
||||||
"value": "Rozmowy na dany temat powinny toczyć się w kanałach do tego przeznaczonych."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "§5 Memy i Gify",
|
|
||||||
"value": "Memy i Gify nie są zbyt przyjemne dla oka bez kontekstu. Najlepiej jest nie postować ich, jeżeli nie pasują do prowadzonej aktualnie dyskusji."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "§6 Reklamy",
|
|
||||||
"value": "Zakaz reklam bez zezwolenia moderatora lub administratora. Pozwolenia na reklamę muszą być wydane przed jej zamieszczeniem."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "§7 Przestrzeganie Regulaminu",
|
|
||||||
"value": "Przestrzeganie regulaminu jest obowiązkowe, a to że go ktoś nie przeczytał nic nie zmienia."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "§8 Obcowanie z botem",
|
|
||||||
"value": "Próby intencjonalnego łamania bota nie są mile widziane, tak jak nadużywanie go w celach spamu kanałów."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "§9 Warunki Użytkowania Discord (ToS)",
|
|
||||||
"value": "Nasz serwer, jak każdy inny, musi przestrzegać zasad zapisanych w warunkach użytkowania Discorda. Przypominamy o nich, bo choć nie są zbyt restrykcyjne, nie pozwalają na kilka określonych rzeczy."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"pomocDesc": "Komenda objaśniająca bota i jego zastosowanie, a także dostępne komendy.\n\nBot Gractwa funkcjonuje jako własne rozwiązanie na problemy z administrowaniem serwera Discord. Umożliwia między innymi samo-nadawanie rolek od gier, lub odsłuchiwanie muzyki.\n\nPoniżej znajduje się lista dostępnych komend:",
|
|
||||||
"rolkiDesc": "Poniżej widnieją przyciski służące do przyznawania bądź odejmowanie sobie ról powiązanych z grami. Służą one do oznaczania wszystkich zainteresowanych daną grą na określonym kanale."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
0
src/cmds/batch.js
Normal file
0
src/cmds/batch.js
Normal file
37
src/cmds/dodajodznake.js
Normal file
37
src/cmds/dodajodznake.js
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
module.exports = {
|
||||||
|
name: "dodajodznake",
|
||||||
|
async execute(cl, msg, args) {
|
||||||
|
const { get } = require("https");
|
||||||
|
const { createWriteStream, access } = require("fs");
|
||||||
|
if (msg.member.permissions.has(0x20)) {
|
||||||
|
if (msg.attachments.at(0) != null) {
|
||||||
|
console.log("attachmentadded");
|
||||||
|
msg.attachments.each((x) => {
|
||||||
|
if (x.contentType.startsWith("application/json")) {
|
||||||
|
access(`src/badges/json/${x.name}`, (e) => {
|
||||||
|
if (!e) {
|
||||||
|
const file = createWriteStream(`src/badges/json/${x.name}`);
|
||||||
|
get(x.url, (res) => {
|
||||||
|
res.pipe(file);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
msg.channel.send("Taka odznaka już istnieje");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (x.contentType.startsWith("image/")) {
|
||||||
|
exists(`src/badges/img/${x.name}`, (e) => {
|
||||||
|
if (!e) {
|
||||||
|
const file = createWriteStream(`src/badges/img/${x.name}`);
|
||||||
|
get(x.url, (res) => {
|
||||||
|
res.pipe(file);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
msg.channel.send("Taka odznaka już istnieje");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -13,11 +13,6 @@ module.exports = {
|
|||||||
// not intended outside of specific scenarios
|
// not intended outside of specific scenarios
|
||||||
let embed = {
|
let embed = {
|
||||||
color: cl.cfg.hexBlue,
|
color: cl.cfg.hexBlue,
|
||||||
// timestamp: new Date(),
|
|
||||||
// footer: {
|
|
||||||
// text: `Komenda wywołana przez ${msg.author.tag}`,
|
|
||||||
// icon_url: cl.cfg.iconurl,
|
|
||||||
// },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let readyMsg;
|
let readyMsg;
|
||||||
|
|||||||
6
src/cmds/odznaki.js
Normal file
6
src/cmds/odznaki.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
module.exports = {
|
||||||
|
name: "odznaki",
|
||||||
|
execute(cl, msg) {
|
||||||
|
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'ping',
|
name: "ping",
|
||||||
execute(cl, msg) {
|
execute(cl, msg) {
|
||||||
const embed = {
|
const embed = {
|
||||||
color: cl.cfg.hexBlue,
|
color: cl.cfg.hexBlue,
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: {
|
footer: {
|
||||||
text: `Komenda wywołana przez ${msg.author.tag}`,
|
text: `Komenda wywołana przez ${msg.author.tag}`,
|
||||||
icon_url: cl.cfg.iconurl,
|
icon_url: cl.cfg.iconurl,
|
||||||
},
|
},
|
||||||
title: 'Pong!',
|
title: "Pong!",
|
||||||
description: `Ping jednostronny wynosi ${
|
description: `Ping jednostronny wynosi ${
|
||||||
Date.now() - msg.createdTimestamp
|
Date.now() - msg.createdTimestamp
|
||||||
}ms.`,
|
}ms.`,
|
||||||
};
|
};
|
||||||
msg.channel.send({ embeds: [embed] });
|
msg.channel.send({ embeds: [embed] });
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
56
src/cmds/profile.js
Normal file
56
src/cmds/profile.js
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
module.exports = {
|
||||||
|
name: "profile",
|
||||||
|
async execute(cl, msg, args, connect) {
|
||||||
|
const { roundRect, expThreshold } = require("../functions/tools");
|
||||||
|
const canvas = require("canvas");
|
||||||
|
await connect
|
||||||
|
.profile(msg.author.id)
|
||||||
|
.then((user) => {
|
||||||
|
canvas.registerFont("./src/fonts/Lexend-Bold.ttf", {
|
||||||
|
family: "LexendBold",
|
||||||
|
});
|
||||||
|
canvas.registerFont("./src/fonts/Lexend-Thin.ttf", {
|
||||||
|
family: "LexendThin",
|
||||||
|
});
|
||||||
|
const canva = canvas.createCanvas(1024, 256);
|
||||||
|
let context = canva.getContext("2d");
|
||||||
|
context.fillStyle = "#484848";
|
||||||
|
roundRect(context, 0, 0, 1024, 256, 25);
|
||||||
|
context.fill();
|
||||||
|
context.font = '48px "LexendBold"';
|
||||||
|
context.fillStyle = "#FFFFFF";
|
||||||
|
context.fillText(msg.author.tag, 244, 24 + 48);
|
||||||
|
context.fillText("Lvl " + user.lvl, 850, 24 + 48);
|
||||||
|
context.font = '25px "LexendThin"';
|
||||||
|
context.fillText(user.msg_count + " messages sent", 244, 72 + 25);
|
||||||
|
context.font = '24px "LexendThin"';
|
||||||
|
context.fillText(expThreshold(user.lvl + 1) + " exp", 810, 164 + 24);
|
||||||
|
context.fillText(user.exp + " exp", 250, 164 + 24);
|
||||||
|
context.fillStyle = "#242424";
|
||||||
|
roundRect(context, 244, 200, 700, 30, 50);
|
||||||
|
context.fill();
|
||||||
|
context.fillStyle = "#61F2EA";
|
||||||
|
roundRect(
|
||||||
|
context,
|
||||||
|
244,
|
||||||
|
200,
|
||||||
|
700 *
|
||||||
|
((user.exp - expThreshold(user.lvl)) / expThreshold(user.lvl + 1)),
|
||||||
|
30,
|
||||||
|
50
|
||||||
|
);
|
||||||
|
context.fill();
|
||||||
|
roundRect(context, 34, 34, 188, 188, 100);
|
||||||
|
canvas
|
||||||
|
.loadImage(msg.author.avatarURL({ format: "png" }))
|
||||||
|
.then((image) => {
|
||||||
|
context.clip();
|
||||||
|
context.drawImage(image, 34, 34, 188, 188);
|
||||||
|
msg.reply({
|
||||||
|
files: [canva.toBuffer()],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((err) => console.error(err.stack));
|
||||||
|
},
|
||||||
|
};
|
||||||
4
src/cmds/ranking.js
Normal file
4
src/cmds/ranking.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
module.exports = {
|
||||||
|
name: "ranking",
|
||||||
|
execute(cl, msg) {},
|
||||||
|
};
|
||||||
BIN
src/fonts/Lexend-Bold.ttf
Normal file
BIN
src/fonts/Lexend-Bold.ttf
Normal file
Binary file not shown.
BIN
src/fonts/Lexend-Thin.ttf
Normal file
BIN
src/fonts/Lexend-Thin.ttf
Normal file
Binary file not shown.
94
src/functions/postgres.js
Normal file
94
src/functions/postgres.js
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
const { lvl, randomExp } = require("./tools");
|
||||||
|
const { PrismaClient } = require("@prisma/client");
|
||||||
|
class Postgres {
|
||||||
|
constructor() {
|
||||||
|
this.client = new PrismaClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
async messageCount(userID) {
|
||||||
|
return await this.client.users.update({
|
||||||
|
where: {
|
||||||
|
user_id: userID,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
msg_count: {
|
||||||
|
increment: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async profile(userID) {
|
||||||
|
return await this.client.users.findUnique({
|
||||||
|
where: {
|
||||||
|
user_id: userID,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async msg_state(userID) {
|
||||||
|
return await this.client.users.findUnique({
|
||||||
|
where: {
|
||||||
|
user_id: userID,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async addExp(userID, min, max) {
|
||||||
|
await this.#ifUserExist(userID).then(async () => {
|
||||||
|
const rExp = randomExp(min, max);
|
||||||
|
return await this.client.users.update({
|
||||||
|
where: {
|
||||||
|
user_id: userID,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
exp: {
|
||||||
|
increment: rExp,
|
||||||
|
},
|
||||||
|
lvl: lvl(
|
||||||
|
(
|
||||||
|
await this.client.users.findUnique({
|
||||||
|
where: {
|
||||||
|
user_id: userID,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
exp: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
).exp
|
||||||
|
),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async #ifUserExist(userID) {
|
||||||
|
if ((await this.profile(userID)) == null) {
|
||||||
|
console.log("Account");
|
||||||
|
await this.client.users.create({
|
||||||
|
data: {
|
||||||
|
user_id: userID,
|
||||||
|
lvl: 0,
|
||||||
|
exp: 0,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async #ifMsgsExist(userID, channelID) {
|
||||||
|
if ((await this.profile(userID)) == null) {
|
||||||
|
console.log("Account");
|
||||||
|
await this.client.users.create({
|
||||||
|
data: {
|
||||||
|
user_id: userID,
|
||||||
|
lvl: 0,
|
||||||
|
exp: 0,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//addBadge: async function (args) {},
|
||||||
|
//giveBadge: async function (args) {},
|
||||||
|
}
|
||||||
|
module.exports.Postgres = Postgres;
|
||||||
19
src/functions/redis.js
Normal file
19
src/functions/redis.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
module.exports = {
|
||||||
|
expCheck: async function (userID, connect) {
|
||||||
|
date = new Date();
|
||||||
|
const user = await connect.get(userID);
|
||||||
|
if (user == null) {
|
||||||
|
await connect.set(userID, date.getTime());
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
date = await connect.get(userID);
|
||||||
|
const currentDate = new Date();
|
||||||
|
if (currentDate.getTime() - date > 60000) {
|
||||||
|
await connect.set(userID, currentDate.getTime());
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
23
src/functions/tools.js
Normal file
23
src/functions/tools.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
module.exports = {
|
||||||
|
lvl: function (exp) {
|
||||||
|
return Math.floor(Math.sqrt(exp) / 5);
|
||||||
|
},
|
||||||
|
expThreshold: function (lvl) {
|
||||||
|
return Math.floor(lvl * lvl * 25);
|
||||||
|
},
|
||||||
|
randomExp: function (min, max) {
|
||||||
|
return Math.floor(Math.random() * (max - min)) + min;
|
||||||
|
},
|
||||||
|
roundRect: function (ctx, x, y, width, height, radius) {
|
||||||
|
if (width < 2 * radius) radius = width / 2;
|
||||||
|
if (height < 2 * radius) radius = height / 2;
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(x + radius, y);
|
||||||
|
ctx.arcTo(x + width, y, x + width, y + height, radius);
|
||||||
|
ctx.arcTo(x + width, y + height, x, y + height, radius);
|
||||||
|
ctx.arcTo(x, y + height, x, y, radius);
|
||||||
|
ctx.arcTo(x, y, x + width, y, radius);
|
||||||
|
ctx.closePath();
|
||||||
|
return ctx;
|
||||||
|
},
|
||||||
|
};
|
||||||
57
src/index.js
57
src/index.js
@@ -1,57 +0,0 @@
|
|||||||
const discordjs = require('discord.js');
|
|
||||||
const fs = require('fs');
|
|
||||||
require('dotenv').config();
|
|
||||||
|
|
||||||
const cl = new discordjs.Client({
|
|
||||||
intents: [
|
|
||||||
discordjs.Intents.FLAGS.GUILDS,
|
|
||||||
discordjs.Intents.FLAGS.GUILD_MESSAGES,
|
|
||||||
],
|
|
||||||
});
|
|
||||||
cl.cfg = require('./cfg.json');
|
|
||||||
cl.cmds = new discordjs.Collection();
|
|
||||||
|
|
||||||
const cmdsFls = fs
|
|
||||||
.readdirSync(`./src/cmds`)
|
|
||||||
.filter((file) => file.endsWith(`.js`));
|
|
||||||
for (const Fl of cmdsFls) {
|
|
||||||
const cmd = require(`./cmds/${Fl}`);
|
|
||||||
console.log(`command: ` + cmd.name);
|
|
||||||
cl.cmds.set(cmd.name, cmd);
|
|
||||||
}
|
|
||||||
|
|
||||||
cl.on('messageCreate', (msg) => {
|
|
||||||
if (!msg.content.startsWith(cl.cfg.prefix) || msg.author.bot) return;
|
|
||||||
|
|
||||||
const args = msg.content.slice(cl.cfg.prefix.length).trim().split(/ +/);
|
|
||||||
const cmdName = args.shift().toLowerCase();
|
|
||||||
|
|
||||||
if (!cl.cmds.has(cmdName)) return;
|
|
||||||
const cmd = cl.cmds.get(cmdName);
|
|
||||||
|
|
||||||
try {
|
|
||||||
cmd.execute(cl, msg, args);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(
|
|
||||||
`msgCommand error: ${cmdName} with args ${args} by ${msg.author.tag}\n--\n${error}\n--`
|
|
||||||
);
|
|
||||||
msg.reply(
|
|
||||||
`An error occured while trying to execute ${cmdName} with args ${args}`
|
|
||||||
);
|
|
||||||
console.log(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.log(`msgCommand: ${cmdName + args} by ${msg.author.tag}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
cl.once('ready', () => {
|
|
||||||
console.clear();
|
|
||||||
console.log(`bot ready; logged in as ${cl.user.tag}\n--`);
|
|
||||||
cl.user.setActivity('.pomoc', { type: 'LISTENING' });
|
|
||||||
});
|
|
||||||
|
|
||||||
cl.login(process.env.token); // here comes the boooy
|
|
||||||
// hello boy
|
|
||||||
// welcome
|
|
||||||
// there he is
|
|
||||||
// he is here
|
|
||||||
Reference in New Issue
Block a user