Compare commits
No commits in common. "60972e57820638cf0773bf21eb14b61b06da9ea9" and "ffff5e8c7f03508efa5f57d95c964dfb8a226962" have entirely different histories.
60972e5782
...
ffff5e8c7f
18 changed files with 4939 additions and 9024 deletions
|
@ -7,7 +7,7 @@ steps:
|
|||
- name: deploy
|
||||
image: appleboy/drone-ssh
|
||||
settings:
|
||||
host: 192.168.1.115
|
||||
host: 192.168.68.120
|
||||
username: vylpes
|
||||
password:
|
||||
from_secret: ssh_password
|
||||
|
@ -28,7 +28,7 @@ steps:
|
|||
- name: stage
|
||||
image: appleboy/drone-ssh
|
||||
settings:
|
||||
host: 192.168.1.115
|
||||
host: 192.168.68.120
|
||||
username: vylpes
|
||||
password:
|
||||
from_secret: ssh_password
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
name: Deploy To Production
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build:
|
||||
environment: prod
|
||||
|
||||
runs-on: node
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 18.x
|
||||
- run: npm ci
|
||||
- run: npm run build
|
||||
- run: npm test
|
||||
|
||||
- name: "Copy files over to location"
|
||||
run: cp -r . ${{ secrets.PROD_REPO_PATH }}
|
||||
|
||||
deploy:
|
||||
environment: prod
|
||||
needs: build
|
||||
runs-on: node
|
||||
steps:
|
||||
- uses: https://github.com/appleboy/ssh-action@v1.0.0
|
||||
env:
|
||||
DB_NAME: ${{ secrets.PROD_DB_NAME }}
|
||||
DB_AUTH_USER: ${{ secrets.PROD_DB_AUTH_USER }}
|
||||
DB_AUTH_PASS: ${{ secrets.PROD_DB_AUTH_PASS }}
|
||||
DB_HOST: ${{ secrets.PROD_DB_HOST }}
|
||||
DB_PORT: ${{ secrets.PROD_DB_PORT }}
|
||||
DB_ROOT_HOST: ${{ secrets.PROD_DB_ROOT_HOST }}
|
||||
DB_SYNC: ${{ secrets.PROD_DB_SYNC }}
|
||||
DB_LOGGING: ${{ secrets.PROD_DB_LOGGING }}
|
||||
DB_DATA_LOCATION: ${{ secrets.PROD_DB_DATA_LOCATION }}
|
||||
SERVER_PATH: ${{ secrets.PROD_SSH_SERVER_PATH }}
|
||||
BOT_TOKEN: ${{ secrets.PROD_BOT_TOKEN }}
|
||||
BOT_VER: ${{ vars.PROD_BOT_VER }}
|
||||
BOT_AUTHOR: ${{ vars.PROD_BOT_AUTHOR }}
|
||||
BOT_OWNERID: ${{ vars.PROD_BOT_OWNERID }}
|
||||
BOT_CLIENTID: ${{ vars.PROD_BOT_CLIENTID }}
|
||||
ABOUT_FUNDING: ${{ vars.PROD_ABOUT_FUNDING }}
|
||||
ABOUT_REPO: ${{ vars.PROD_ABOUT_REPO }}
|
||||
CACHE_INTERVAL: ${{ vars.PROD_CACHE_INTERVAL }}
|
||||
with:
|
||||
host: ${{ secrets.PROD_SSH_HOST }}
|
||||
username: ${{ secrets.PROD_SSH_USER }}
|
||||
key: ${{ secrets.PROD_SSH_KEY }}
|
||||
port: ${{ secrets.PROD_SSH_PORT }}
|
||||
envs: DB_NAME,DB_AUTH_USER,DB_AUTH_PASS,DB_HOST,DB_PORT,DB_ROOT_HOST,DB_SYNC,DB_LOGGING,DB_DATA_LOCATION,BOT_TOKEN,BOT_VER,BOT_AUTHOR,BOT_OWNERID,BOT_CLIENTID,ABOUT_FUNDING,ABOUT_REPO,CACHE_INTERVAL
|
||||
script: |
|
||||
source .sshrc \
|
||||
&& cd /home/vylpes/apps/vylbot/vylbot_prod \
|
||||
&& docker compose down \
|
||||
&& (pm2 stop vylbot_prod || true) \
|
||||
&& (pm2 delete vylbot_prod || true) \
|
||||
&& docker compose up -d \
|
||||
&& sleep 10 \
|
||||
&& npm run db:up \
|
||||
&& pm2 start --name vylbot_prod dist/vylbot.js
|
|
@ -1,67 +0,0 @@
|
|||
name: Deploy To Stage
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- develop
|
||||
|
||||
jobs:
|
||||
build:
|
||||
environment: prod
|
||||
|
||||
runs-on: node
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 18.x
|
||||
- run: npm ci
|
||||
- run: npm run build
|
||||
- run: npm test
|
||||
|
||||
- name: "Copy files over to location"
|
||||
run: cp -r . ${{ secrets.STAGE_REPO_PATH }}
|
||||
|
||||
deploy:
|
||||
environment: prod
|
||||
needs: build
|
||||
runs-on: node
|
||||
steps:
|
||||
- uses: https://github.com/appleboy/ssh-action@v1.0.0
|
||||
env:
|
||||
DB_NAME: ${{ secrets.STAGE_DB_NAME }}
|
||||
DB_AUTH_USER: ${{ secrets.STAGE_DB_AUTH_USER }}
|
||||
DB_AUTH_PASS: ${{ secrets.STAGE_DB_AUTH_PASS }}
|
||||
DB_HOST: ${{ secrets.STAGE_DB_HOST }}
|
||||
DB_PORT: ${{ secrets.STAGE_DB_PORT }}
|
||||
DB_ROOT_HOST: ${{ secrets.STAGE_DB_ROOT_HOST }}
|
||||
DB_SYNC: ${{ secrets.STAGE_DB_SYNC }}
|
||||
DB_LOGGING: ${{ secrets.STAGE_DB_LOGGING }}
|
||||
DB_DATA_LOCATION: ${{ secrets.STAGE_DB_DATA_LOCATION }}
|
||||
SERVER_PATH: ${{ secrets.STAGE_SSH_SERVER_PATH }}
|
||||
BOT_TOKEN: ${{ secrets.STAGE_BOT_TOKEN }}
|
||||
BOT_VER: ${{ vars.STAGE_BOT_VER }}
|
||||
BOT_AUTHOR: ${{ vars.STAGE_BOT_AUTHOR }}
|
||||
BOT_OWNERID: ${{ vars.STAGE_BOT_OWNERID }}
|
||||
BOT_CLIENTID: ${{ vars.STAGE_BOT_CLIENTID }}
|
||||
ABOUT_FUNDING: ${{ vars.STAGE_ABOUT_FUNDING }}
|
||||
ABOUT_REPO: ${{ vars.STAGE_ABOUT_REPO }}
|
||||
CACHE_INTERVAL: ${{ vars.STAGE_CACHE_INTERVAL }}
|
||||
with:
|
||||
host: ${{ secrets.STAGE_SSH_HOST }}
|
||||
username: ${{ secrets.STAGE_SSH_USER }}
|
||||
key: ${{ secrets.STAGE_SSH_KEY }}
|
||||
port: ${{ secrets.STAGE_SSH_PORT }}
|
||||
envs: DB_NAME,DB_AUTH_USER,DB_AUTH_PASS,DB_HOST,DB_PORT,DB_ROOT_HOST,DB_SYNC,DB_LOGGING,DB_DATA_LOCATION,BOT_TOKEN,BOT_VER,BOT_AUTHOR,BOT_OWNERID,BOT_CLIENTID,ABOUT_FUNDING,ABOUT_REPO,CACHE_INTERVAL
|
||||
script: |
|
||||
source .sshrc \
|
||||
&& cd /home/vylpes/apps/vylbot/vylbot_stage \
|
||||
&& docker compose down \
|
||||
&& (pm2 stop vylbot_stage || true) \
|
||||
&& (pm2 delete vylbot_stage || true) \
|
||||
&& docker compose up -d \
|
||||
&& sleep 10 \
|
||||
&& npm run db:up \
|
||||
&& pm2 start --name vylbot_stage dist/vylbot.js
|
|
@ -1,24 +0,0 @@
|
|||
name: Test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- feature/*
|
||||
- hotfix/*
|
||||
- renovate/*
|
||||
|
||||
jobs:
|
||||
build:
|
||||
environment: stage
|
||||
|
||||
runs-on: node
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 18.x
|
||||
- run: npm ci
|
||||
- run: npm run build
|
||||
- run: npm test
|
26
.prod.env
Normal file
26
.prod.env
Normal file
|
@ -0,0 +1,26 @@
|
|||
# Security Warning! Do not commit this file to any VCS!
|
||||
# This is a local file to speed up development process,
|
||||
# so you don't have to change your environment variables.
|
||||
#
|
||||
# This is not applied to `.env.template`!
|
||||
# Template files must be committed to the VCS, but must not contain
|
||||
# any secret values.
|
||||
|
||||
BOT_TOKEN=
|
||||
BOT_VER=3.3.0
|
||||
BOT_AUTHOR=Vylpes
|
||||
BOT_OWNERID=147392775707426816
|
||||
BOT_CLIENTID=680083120896081954
|
||||
|
||||
ABOUT_FUNDING=https://ko-fi.com/vylpes
|
||||
ABOUT_REPO=https://gitea.vylpes.xyz/RabbitLabs/vylbot-app
|
||||
|
||||
CACHE_INTERVAL=1800000 # 30 minutes
|
||||
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=3121
|
||||
DB_NAME=vylbot
|
||||
DB_AUTH_USER=prod
|
||||
DB_AUTH_PASS=prod
|
||||
DB_SYNC=false
|
||||
DB_LOGGING=false
|
26
.stage.env
Normal file
26
.stage.env
Normal file
|
@ -0,0 +1,26 @@
|
|||
# Security Warning! Do not commit this file to any VCS!
|
||||
# This is a local file to speed up development process,
|
||||
# so you don't have to change your environment variables.
|
||||
#
|
||||
# This is not applied to `.env.template`!
|
||||
# Template files must be committed to the VCS, but must not contain
|
||||
# any secret values.
|
||||
|
||||
BOT_TOKEN=
|
||||
BOT_VER=3.3.0
|
||||
BOT_AUTHOR=Vylpes
|
||||
BOT_OWNERID=147392775707426816
|
||||
BOT_CLIENTID=1016767908740857949
|
||||
|
||||
ABOUT_FUNDING=https://ko-fi.com/vylpes
|
||||
ABOUT_REPO=https://gitea.vylpes.xyz/RabbitLabs/vylbot-app
|
||||
|
||||
CACHE_INTERVAL=1800000 # 30 minutes
|
||||
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=3111
|
||||
DB_NAME=vylbot
|
||||
DB_AUTH_USER=stage
|
||||
DB_AUTH_PASS=stage
|
||||
DB_SYNC=false
|
||||
DB_LOGGING=false
|
31
docker-compose.prod.yml
Normal file
31
docker-compose.prod.yml
Normal file
|
@ -0,0 +1,31 @@
|
|||
version: "3.9"
|
||||
|
||||
volumes:
|
||||
prod_database_data:
|
||||
|
||||
services:
|
||||
# discord:
|
||||
# build: .
|
||||
|
||||
database:
|
||||
image: mysql/mysql-server
|
||||
command: --default-authentication-plugin=mysql_native_password
|
||||
restart: always
|
||||
environment:
|
||||
- MYSQL_DATABASE=vylbot
|
||||
- MYSQL_USER=prod
|
||||
- MYSQL_PASSWORD=prod
|
||||
- MYSQL_ROOT_PASSWORD=root
|
||||
- MYSQL_ROOT_HOST=0.0.0.0
|
||||
ports:
|
||||
- "3121:3306"
|
||||
volumes:
|
||||
- prod_database_data:/var/lib/mysql
|
||||
|
||||
phpmyadmin:
|
||||
image: phpmyadmin
|
||||
restart: always
|
||||
ports:
|
||||
- "3122:80"
|
||||
environment:
|
||||
- PMA_ARBITRARY=1
|
31
docker-compose.stage.yml
Normal file
31
docker-compose.stage.yml
Normal file
|
@ -0,0 +1,31 @@
|
|||
version: "3.9"
|
||||
|
||||
volumes:
|
||||
stage_database_data:
|
||||
|
||||
services:
|
||||
# discord:
|
||||
# build: .
|
||||
|
||||
database:
|
||||
image: mysql/mysql-server
|
||||
command: --default-authentication-plugin=mysql_native_password
|
||||
restart: always
|
||||
environment:
|
||||
- MYSQL_DATABASE=vylbot
|
||||
- MYSQL_USER=stage
|
||||
- MYSQL_PASSWORD=stage
|
||||
- MYSQL_ROOT_PASSWORD=root
|
||||
- MYSQL_ROOT_HOST=0.0.0.0
|
||||
ports:
|
||||
- "3111:3306"
|
||||
volumes:
|
||||
- stage_database_data:/var/lib/mysql
|
||||
|
||||
phpmyadmin:
|
||||
image: phpmyadmin
|
||||
restart: always
|
||||
ports:
|
||||
- "3112:80"
|
||||
environment:
|
||||
- PMA_ARBITRARY=1
|
|
@ -1,17 +1,31 @@
|
|||
version: "3.9"
|
||||
|
||||
volumes:
|
||||
dev_database_data:
|
||||
|
||||
services:
|
||||
# discord:
|
||||
# build: .
|
||||
|
||||
database:
|
||||
image: mysql/mysql-server
|
||||
command: --default-authentication-plugin=mysql_native_password
|
||||
restart: always
|
||||
environment:
|
||||
- MYSQL_DATABASE=$DB_NAME
|
||||
- MYSQL_USER=$DB_AUTH_USER
|
||||
- MYSQL_PASSWORD=$DB_AUTH_PASS
|
||||
- MYSQL_ROOT_PASSWORD=$DB_AUTH_PASS
|
||||
- MYSQL_ROOT_HOST=$DB_ROOT_HOST
|
||||
- MYSQL_DATABASE=vylbot
|
||||
- MYSQL_USER=dev
|
||||
- MYSQL_PASSWORD=dev
|
||||
- MYSQL_ROOT_PASSWORD=root
|
||||
- MYSQL_ROOT_HOST=0.0.0.0
|
||||
ports:
|
||||
- "$DB_PORT:3306"
|
||||
- "3101:3306"
|
||||
volumes:
|
||||
- $DB_DATA_LOCATION:/var/lib/mysql
|
||||
- dev_database_data:/var/lib/mysql
|
||||
|
||||
phpmyadmin:
|
||||
image: phpmyadmin
|
||||
restart: always
|
||||
ports:
|
||||
- "3102:80"
|
||||
environment:
|
||||
- PMA_ARBITRARY=1
|
8815
package-lock.json
generated
8815
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "vylbot-app",
|
||||
"version": "3.2.2",
|
||||
"version": "3.2.1",
|
||||
"description": "A discord bot made for Vylpes' Den",
|
||||
"main": "./dist/vylbot",
|
||||
"typings": "./dist",
|
||||
|
@ -37,7 +37,7 @@
|
|||
"jest-mock-extended": "^3.0.0",
|
||||
"minimatch": "9.0.3",
|
||||
"mysql": "^2.18.1",
|
||||
"random-bunny": "^2.1.6",
|
||||
"random-bunny": "^2.0.5",
|
||||
"ts-jest": "^29.0.0",
|
||||
"typeorm": "0.3.20"
|
||||
},
|
||||
|
|
|
@ -15,8 +15,6 @@ export default class Bunny extends Command {
|
|||
public override async execute(interaction: CommandInteraction) {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
||||
await interaction.deferReply();
|
||||
|
||||
const subreddits = [
|
||||
'rabbits',
|
||||
'bunnieswithhats',
|
||||
|
@ -26,7 +24,6 @@ export default class Bunny extends Command {
|
|||
];
|
||||
|
||||
const random = Math.floor(Math.random() * subreddits.length);
|
||||
|
||||
const selectedSubreddit = subreddits[random];
|
||||
|
||||
const result = await randomBunny(selectedSubreddit, 'hot');
|
||||
|
@ -40,9 +37,9 @@ export default class Bunny extends Command {
|
|||
.setURL(`https://reddit.com${result.Result!.Permalink}`)
|
||||
.setFooter({ text: `r/${selectedSubreddit} · ${result.Result!.Ups} upvotes`});
|
||||
|
||||
await interaction.editReply({ embeds: [ embed ]});
|
||||
await interaction.reply({ embeds: [ embed ]});
|
||||
} else {
|
||||
await interaction.editReply("There was an error running this command.");
|
||||
await interaction.reply("There was an error running this command.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ export default class Unmute extends Command {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
this.CommandBuilder = new SlashCommandBuilder()
|
||||
super.CommandBuilder = new SlashCommandBuilder()
|
||||
.setName("unmute")
|
||||
.setDescription("(DEPRECATED) Unmute a member in the server with an optional reason")
|
||||
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
|
||||
|
|
|
@ -3,9 +3,7 @@ import NicknameChanged from "./GuildMemberUpdate/NicknameChanged";
|
|||
import CacheHelper from "../../helpers/CacheHelper";
|
||||
|
||||
export default async function GuildMemberUpdate(oldMember: GuildMember, newMember: GuildMember) {
|
||||
const updatedFromCache = await CacheHelper.UpdateServerCache(newMember.guild);
|
||||
|
||||
if (updatedFromCache) return;
|
||||
await CacheHelper.UpdateServerCache(newMember.guild);
|
||||
|
||||
if (oldMember.nickname !== newMember.nickname) { // Nickname change
|
||||
await NicknameChanged(oldMember, newMember);
|
||||
|
|
|
@ -2,10 +2,10 @@ import { Guild } from "discord.js";
|
|||
import Server from "../database/entities/Server";
|
||||
|
||||
export default class CacheHelper {
|
||||
public static async UpdateServerCache(guild: Guild): Promise<boolean> {
|
||||
public static async UpdateServerCache(guild: Guild) {
|
||||
const cacheInterval = process.env.CACHE_INTERVAL;
|
||||
|
||||
if (!cacheInterval) return false;
|
||||
if (!cacheInterval) return;
|
||||
|
||||
let server = await Server.FetchOneById(Server, guild.id);
|
||||
|
||||
|
@ -14,15 +14,9 @@ export default class CacheHelper {
|
|||
await server.Save(Server, server);
|
||||
|
||||
await CacheHelper.UpdateCache(guild);
|
||||
|
||||
return true;
|
||||
} else if (server.LastCached.getTime() + Number(cacheInterval) > Date.now()) {
|
||||
} else if (server.LastCached.getTime() + Number(cacheInterval) < Date.now()) {
|
||||
await CacheHelper.UpdateCache(guild);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static async UpdateCache(guild: Guild) {
|
||||
|
|
|
@ -28,10 +28,9 @@ describe('execute', () => {
|
|||
|
||||
const interaction = {
|
||||
isChatInputCommand: jest.fn().mockReturnValue(true),
|
||||
editReply: jest.fn().mockImplementation((options) => {
|
||||
reply: jest.fn().mockImplementation((options) => {
|
||||
repliedWith = options;
|
||||
}),
|
||||
deferReply: jest.fn(),
|
||||
} as unknown as CommandInteraction;
|
||||
|
||||
jest.spyOn(randomBunny, "default").mockResolvedValue({
|
||||
|
@ -47,11 +46,6 @@ describe('execute', () => {
|
|||
Subreddit: "rabbits",
|
||||
SubredditSubscribers: 1,
|
||||
},
|
||||
Error: undefined,
|
||||
Query: {
|
||||
subreddit: "rabbits",
|
||||
sortBy: "hot",
|
||||
},
|
||||
});
|
||||
|
||||
Math.floor = jest.fn().mockReturnValue(0);
|
||||
|
@ -62,9 +56,7 @@ describe('execute', () => {
|
|||
expect(randomBunny.default).toHaveBeenCalledTimes(1);
|
||||
expect(randomBunny.default).toHaveBeenCalledWith("rabbits", "hot");
|
||||
|
||||
expect(interaction.editReply).toHaveBeenCalledTimes(1);
|
||||
expect(interaction.deferReply).toHaveBeenCalledTimes(1);
|
||||
|
||||
expect(interaction.reply).toHaveBeenCalledTimes(1);
|
||||
expect(repliedWith).toBeDefined();
|
||||
expect(repliedWith!.embeds).toBeDefined();
|
||||
expect(repliedWith!.embeds.length).toBe(1);
|
||||
|
@ -96,18 +88,12 @@ describe('execute', () => {
|
|||
test("GIVEN a result from random-bunny is failure, EXPECT error", async () => {
|
||||
const interaction = {
|
||||
isChatInputCommand: jest.fn().mockReturnValue(true),
|
||||
editReply: jest.fn(),
|
||||
deferReply: jest.fn(),
|
||||
reply: jest.fn(),
|
||||
} as unknown as CommandInteraction;
|
||||
|
||||
jest.spyOn(randomBunny, "default").mockResolvedValue({
|
||||
IsSuccess: false,
|
||||
Result: undefined,
|
||||
Error: undefined,
|
||||
Query: {
|
||||
subreddit: "rabbits",
|
||||
sortBy: "hot",
|
||||
},
|
||||
Result: undefined
|
||||
});
|
||||
|
||||
Math.floor = jest.fn().mockReturnValue(0);
|
||||
|
@ -117,9 +103,7 @@ describe('execute', () => {
|
|||
|
||||
expect(randomBunny.default).toHaveBeenCalledTimes(1);
|
||||
|
||||
expect(interaction.editReply).toHaveBeenCalledTimes(1);
|
||||
expect(interaction.editReply).toHaveBeenCalledWith("There was an error running this command.");
|
||||
|
||||
expect(interaction.deferReply).toHaveBeenCalledTimes(1);
|
||||
expect(interaction.reply).toHaveBeenCalledTimes(1);
|
||||
expect(interaction.reply).toHaveBeenCalledWith("There was an error running this command.");
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue