Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60f534be1e
|
No files matched your search
@@ -1,13 +0,0 @@
|
||||
name: Build and push image
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
release-image:
|
||||
runs-on: imgbuilder
|
||||
steps:
|
||||
- name: Build and push image
|
||||
uses: https://gitea.konchin.com/action/docker@main
|
||||
with:
|
||||
registry-certificate: ${{ vars.ROOTCA }}
|
||||
username: ${{ secrets.REGISTRY_USERNAME }}
|
||||
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||
+1
-130
@@ -1,131 +1,2 @@
|
||||
# ---> Node
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional stylelint cache
|
||||
.stylelintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
out
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# vuepress v2.x temp and cache directory
|
||||
.temp
|
||||
.cache
|
||||
|
||||
# Docusaurus cache and generated files
|
||||
.docusaurus
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
amane
|
||||
+5
-8
@@ -1,10 +1,7 @@
|
||||
FROM node:22.4-slim AS build
|
||||
WORKDIR /work
|
||||
COPY . /work
|
||||
RUN npm ci && npm run build
|
||||
#FROM gcr.io/distroless/static-debian12
|
||||
FROM gitea.konchin.com/image/alpine:main
|
||||
|
||||
FROM gcr.io/distroless/nodejs22-debian12
|
||||
WORKDIR /work
|
||||
COPY --from=build /work /work
|
||||
ADD amane /amane
|
||||
|
||||
CMD ["index.js"]
|
||||
WORKDIR /
|
||||
ENTRYPOINT ["/amane"]
|
||||
@@ -0,0 +1,27 @@
|
||||
.PHONY: all swagger docker install test sh
|
||||
|
||||
SWAG ?= ~/go/bin/swag
|
||||
|
||||
GO_ENV += CGO_ENABLED=0
|
||||
TARGET := $(shell find . -type f -name '*.go')
|
||||
|
||||
all: swagger docker install
|
||||
|
||||
docker: amane
|
||||
docker compose up -d --force-recreate --build backend
|
||||
|
||||
install:
|
||||
$(GO_ENV) go install
|
||||
|
||||
test:
|
||||
go test -v ./tests/units
|
||||
|
||||
swagger:
|
||||
$(SWAG) fmt
|
||||
$(SWAG) init -o handlers/docs -g cmd/backend.go -pdl 1
|
||||
|
||||
amane: $(TARGET)
|
||||
$(GO_ENV) go build -o $@
|
||||
|
||||
sh:
|
||||
docker compose exec -it backend sh
|
||||
@@ -1,23 +0,0 @@
|
||||
import {
|
||||
SlashCommandBuilder,
|
||||
SlashCommandSubcommandsOnlyBuilder,
|
||||
CommandInteraction
|
||||
} from 'discord.js';
|
||||
|
||||
export interface Component{
|
||||
execute(interaction: unknown): Promise<void>;
|
||||
build(): unknown;
|
||||
};
|
||||
|
||||
export abstract class Command implements Component{
|
||||
abstract get name(): string;
|
||||
abstract get description(): string;
|
||||
abstract execute(interaction: CommandInteraction): Promise<void>;
|
||||
build():
|
||||
SlashCommandBuilder | SlashCommandSubcommandsOnlyBuilder |
|
||||
Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup">{
|
||||
return new SlashCommandBuilder()
|
||||
.setName(this.name)
|
||||
.setDescription(this.description);
|
||||
}
|
||||
};
|
||||
@@ -1,22 +0,0 @@
|
||||
import {
|
||||
Client,
|
||||
Collection,
|
||||
ClientOptions,
|
||||
} from 'discord.js';
|
||||
|
||||
import {Command} from './command'
|
||||
|
||||
export function isExtendedClient(client: Client): client is ExtendedClient{
|
||||
return (client as ExtendedClient).commands !== undefined;
|
||||
}
|
||||
|
||||
export class ExtendedClient extends Client{
|
||||
public commands: Collection<string, Command>;
|
||||
constructor(
|
||||
opts: ClientOptions,
|
||||
cmds = new Collection<string, Command>()
|
||||
){
|
||||
super(opts);
|
||||
this.commands = cmds;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,84 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
httpSwagger "github.com/swaggo/http-swagger"
|
||||
"github.com/uptrace/bun"
|
||||
"github.com/uptrace/bun/dialect/pgdialect"
|
||||
"github.com/uptrace/bun/driver/pgdriver"
|
||||
"github.com/uptrace/bun/extra/bunotel"
|
||||
"github.com/uptrace/bunrouter"
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"gitea.konchin.com/service/amane-tanikaze-dcbot/amane/handlers/api"
|
||||
_ "gitea.konchin.com/service/amane-tanikaze-dcbot/amane/handlers/docs"
|
||||
"gitea.konchin.com/service/amane-tanikaze-dcbot/amane/middlewares"
|
||||
"gitea.konchin.com/service/amane-tanikaze-dcbot/amane/tracing"
|
||||
)
|
||||
|
||||
// @Title Amane Tanikaze Discord Bot Backend
|
||||
// @Version 2.0-alpha1
|
||||
// @TermsOfService http://swagger.io/terms/
|
||||
|
||||
// @License.Name 0BSD
|
||||
// @BasePath /
|
||||
var backendCmd = &cobra.Command{
|
||||
Use: "backend",
|
||||
Short: "backend server",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
ctx := cmd.Context()
|
||||
tracing.InitTracer()
|
||||
|
||||
sqldb := sql.OpenDB(pgdriver.NewConnector(pgdriver.WithDSN(
|
||||
viper.GetString("pg-dsn"))))
|
||||
db := bun.NewDB(sqldb, pgdialect.New())
|
||||
db.AddQueryHook(bunotel.NewQueryHook(bunotel.WithDBName("PostgreSQL")))
|
||||
|
||||
router := bunrouter.New()
|
||||
|
||||
middlewaresHandlers := middlewares.NewHandlers(db)
|
||||
|
||||
backend := router.NewGroup("").
|
||||
Use(middlewaresHandlers.ErrorHandler)
|
||||
|
||||
if viper.GetBool("swagger") {
|
||||
backend.GET("/docs/*any",
|
||||
bunrouter.HTTPHandlerFunc(httpSwagger.Handler()))
|
||||
}
|
||||
|
||||
apiHandlers := api.NewHandlers(db)
|
||||
|
||||
apiGroup := backend.NewGroup("/api")
|
||||
apiGroup.GET("/image",
|
||||
apiHandlers.GetImage)
|
||||
|
||||
tracing.Logger.Ctx(ctx).
|
||||
Info("http server up",
|
||||
zap.String("http.port", viper.GetString("port")))
|
||||
|
||||
log.Println(http.ListenAndServe(":"+viper.GetString("port"),
|
||||
otelhttp.NewHandler(router, "")))
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
backendCmd.Flags().
|
||||
String("port", "8080", "Port to listen on")
|
||||
|
||||
backendCmd.Flags().
|
||||
String("pg-dsn",
|
||||
"postgres://amane:amane@postgres:5432/amane?sslmode=disable",
|
||||
"PostgreSQL connection string")
|
||||
|
||||
backendCmd.Flags().
|
||||
Bool("zap-develop", false, "Enable development log")
|
||||
|
||||
backendCmd.Flags().
|
||||
Bool("swagger", false, "Enable swagger")
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package cmd
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
var dcbotCmd = &cobra.Command{
|
||||
Use: "dcbot",
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package migrates
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var initCmd = &cobra.Command{
|
||||
Use: "init",
|
||||
Short: "Initialize migration table",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
ctx := cmd.Context()
|
||||
|
||||
return migrator.Init(ctx)
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package migrates
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var lockCmd = &cobra.Command{
|
||||
Use: "lock",
|
||||
Short: "Lock migrations",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return migrator.Lock(cmd.Context())
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package migrates
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var rollbackCmd = &cobra.Command{
|
||||
Use: "rollback",
|
||||
Short: "Rollback from last migration group",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
ctx := cmd.Context()
|
||||
|
||||
if err := migrator.Lock(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
defer migrator.Unlock(ctx)
|
||||
|
||||
group, err := migrator.Rollback(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if group.IsZero() {
|
||||
fmt.Printf("there are no groups to roll back\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
fmt.Printf("roll back from %s\n", group)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package migrates
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"gitea.konchin.com/service/amane-tanikaze-dcbot/amane/migrations"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/uptrace/bun"
|
||||
"github.com/uptrace/bun/dialect/pgdialect"
|
||||
"github.com/uptrace/bun/driver/pgdriver"
|
||||
"github.com/uptrace/bun/extra/bundebug"
|
||||
"github.com/uptrace/bun/migrate"
|
||||
)
|
||||
|
||||
var (
|
||||
migrator *migrate.Migrator
|
||||
db *bun.DB
|
||||
)
|
||||
|
||||
var RootCmd = &cobra.Command{
|
||||
Use: "migrate",
|
||||
Short: "Migration related commands",
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||
sqldb := sql.OpenDB(pgdriver.NewConnector(
|
||||
pgdriver.WithDSN(viper.GetString("pg-dsn"))))
|
||||
db = bun.NewDB(sqldb, pgdialect.New())
|
||||
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))
|
||||
|
||||
migrator = migrate.NewMigrator(db, migrations.Migrations)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
RootCmd.AddCommand(upCmd)
|
||||
RootCmd.AddCommand(initCmd)
|
||||
RootCmd.AddCommand(rollbackCmd)
|
||||
RootCmd.AddCommand(lockCmd)
|
||||
RootCmd.AddCommand(unlockCmd)
|
||||
RootCmd.PersistentFlags().
|
||||
String("pg-dsn",
|
||||
"postgres://amane:amane@postgres:5432/amane?sslmode=disable",
|
||||
"Postgres connection string")
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package migrates
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
var unlockCmd = &cobra.Command{
|
||||
Use: "unlock",
|
||||
Short: "Unlock migrations",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return migrator.Unlock(cmd.Context())
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package migrates
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var upCmd = &cobra.Command{
|
||||
Use: "up",
|
||||
Short: "migrate up",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
ctx := cmd.Context()
|
||||
|
||||
if err := migrator.Lock(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
defer migrator.Unlock(ctx)
|
||||
|
||||
group, err := migrator.Migrate(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if group.IsZero() {
|
||||
fmt.Printf("there are no new migrations to run\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
fmt.Printf("migrated to %s\n", group)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"gitea.konchin.com/service/amane-tanikaze-dcbot/amane/cmd/migrates"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var RootCmd = &cobra.Command{
|
||||
Use: "amane",
|
||||
Short: "Amane Tanikaze Discord Bot",
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||
viper.AutomaticEnv()
|
||||
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
|
||||
viper.BindPFlags(cmd.PersistentFlags())
|
||||
viper.BindPFlags(cmd.Flags())
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
cobra.EnableTraverseRunHooks = true
|
||||
RootCmd.AddCommand(dcbotCmd)
|
||||
RootCmd.AddCommand(backendCmd)
|
||||
RootCmd.AddCommand(migrates.RootCmd)
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
import discord, {
|
||||
CommandInteraction,
|
||||
CommandInteractionOptionResolver,
|
||||
SlashCommandBuilder,
|
||||
SlashCommandRoleOption,
|
||||
SlashCommandStringOption,
|
||||
SlashCommandIntegerOption,
|
||||
SlashCommandSubcommandBuilder,
|
||||
EmbedBuilder,
|
||||
InteractionResponse,
|
||||
SlashCommandSubcommandsOnlyBuilder,
|
||||
} from 'discord.js';
|
||||
import {HydratedDocument} from 'mongoose';
|
||||
|
||||
import {Command} from '../../classes/command';
|
||||
import {logger} from '../../logger';
|
||||
import {config} from '../../config';
|
||||
import {Guild, guildModel} from '../../models/Guild';
|
||||
import {GiveawayMsg, giveawayMsgModel} from '../../models/GiveawayMsg';
|
||||
|
||||
type CIOR = CommandInteractionOptionResolver;
|
||||
|
||||
async function add(interaction: CommandInteraction): Promise<void>{
|
||||
const message: string | null =
|
||||
(interaction.options as CIOR).getString('message');
|
||||
if(!message)
|
||||
throw Error('message not exist');
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle('New Giveaway')
|
||||
.setDescription(`@everyone\n${message}`);
|
||||
|
||||
if(!interaction.guildId)
|
||||
throw Error('guildId not exist');
|
||||
if(!interaction.channelId)
|
||||
throw Error('channelId not exist');
|
||||
|
||||
let msg: discord.Message =
|
||||
await (await interaction.reply({embeds: [embed]})).fetch();
|
||||
await msg.react(config.giveaway.emoji);
|
||||
if(!interaction.guild || !interaction.guild.id)
|
||||
throw Error('guild not exist');
|
||||
const guild: HydratedDocument<Guild> | null =
|
||||
await guildModel.findOneAndUpdate(
|
||||
{id: interaction.guild.id},
|
||||
{$set: {name: interaction.guild.name}},
|
||||
{upsert: true, new: true}
|
||||
);
|
||||
if(!guild)
|
||||
throw Error('guild not exist');
|
||||
const giveawayMsg: HydratedDocument<GiveawayMsg> | null =
|
||||
await giveawayMsgModel.findOneAndUpdate(
|
||||
{guild: guild, messageId: msg.id, authorId: interaction.user.id},
|
||||
{}, {upsert: true, new: true}
|
||||
);
|
||||
if(!giveawayMsg)
|
||||
throw Error('giveawayMsg not exist');
|
||||
|
||||
await msg.edit({embeds: [new EmbedBuilder()
|
||||
.setColor(Math.floor(Math.random()*16777215))
|
||||
.setTitle('Giveaway')
|
||||
.setDescription(message)
|
||||
.setFooter({text: `id: ${msg.id}`})
|
||||
]});
|
||||
}
|
||||
|
||||
async function pick(interaction: CommandInteraction): Promise<void>{
|
||||
const messageId: string | null =
|
||||
(interaction.options as CIOR).getString('message');
|
||||
if(!messageId)
|
||||
throw Error('message not exist');
|
||||
const num: number | null =
|
||||
(interaction.options as CIOR).getInteger('number');
|
||||
if(!num)
|
||||
throw Error('number not exist');
|
||||
|
||||
const dbGiveawayMsg: HydratedDocument<GiveawayMsg> | null =
|
||||
await giveawayMsgModel.findOneAndDelete({
|
||||
messageId: messageId, authorId: interaction.user.id
|
||||
});
|
||||
if(!dbGiveawayMsg){
|
||||
await interaction.reply({
|
||||
content: logger.log(`Giveaway didn't exist or the author didn't match.`),
|
||||
ephemeral: true
|
||||
});
|
||||
return;
|
||||
}
|
||||
for(let i = dbGiveawayMsg.userIds.length - 1; i > 0; i--){
|
||||
let j = Math.floor(Math.random() * (i + 1));
|
||||
[dbGiveawayMsg.userIds[i], dbGiveawayMsg.userIds[j]]
|
||||
= [dbGiveawayMsg.userIds[j], dbGiveawayMsg.userIds[i]];
|
||||
}
|
||||
let content: string = '### Giveaway Result\n';
|
||||
for(let i = 0; i < num; i++)
|
||||
content += `1. ${await interaction.client.users.fetch(dbGiveawayMsg.userIds[i])}\n`;
|
||||
content += `will obtain the prize for giveaway, id: ${dbGiveawayMsg.messageId}`;
|
||||
await interaction.reply({content: content});
|
||||
}
|
||||
|
||||
class Giveaway extends Command{
|
||||
get name(){return 'giveaway';}
|
||||
get description(){return 'Setup a Giveaway message.';}
|
||||
async execute(interaction: CommandInteraction): Promise<void>{
|
||||
try{
|
||||
const subcommand: string | null =
|
||||
(interaction.options as CIOR).getSubcommand();
|
||||
switch(subcommand){
|
||||
case 'add':
|
||||
await add(interaction); break;
|
||||
case 'pick':
|
||||
await pick(interaction); break;
|
||||
default:
|
||||
throw Error('subcommand not exist');
|
||||
}
|
||||
}catch(err: unknown){
|
||||
let message;
|
||||
if(err instanceof Error) message = err.message;
|
||||
else message = String(message);
|
||||
logger.error(`While executing "/giveaway", ${message}`);
|
||||
await interaction.reply({content: `While executing "/giveaway", ${message}`});
|
||||
}
|
||||
}
|
||||
override build(): SlashCommandSubcommandsOnlyBuilder{
|
||||
return new SlashCommandBuilder()
|
||||
.setName(this.name)
|
||||
.setDescription(this.description)
|
||||
.addSubcommand((subcommand: SlashCommandSubcommandBuilder) => subcommand
|
||||
.setName('add')
|
||||
.setDescription('Construct a giveaway')
|
||||
.addStringOption((option: SlashCommandStringOption) => option
|
||||
.setName('message')
|
||||
.setDescription('The message displayed with the giveaway message.')
|
||||
.setRequired(true)
|
||||
)
|
||||
)
|
||||
.addSubcommand((subcommand: SlashCommandSubcommandBuilder) => subcommand
|
||||
.setName('pick')
|
||||
.setDescription('Random pick a number of user in a giveaway')
|
||||
.addStringOption((option: SlashCommandStringOption) => option
|
||||
.setName('message')
|
||||
.setDescription('The message id of the giveaway (Shown in the footer)')
|
||||
.setRequired(true)
|
||||
)
|
||||
.addIntegerOption((option: SlashCommandIntegerOption) => option
|
||||
.setName('number')
|
||||
.setDescription('The number of member to choose.')
|
||||
.setRequired(true)
|
||||
)
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
export const command = new Giveaway();
|
||||
@@ -1,221 +0,0 @@
|
||||
import discord, {
|
||||
CommandInteraction,
|
||||
CommandInteractionOptionResolver,
|
||||
SlashCommandBuilder,
|
||||
SlashCommandStringOption,
|
||||
SlashCommandAttachmentOption,
|
||||
SlashCommandSubcommandBuilder,
|
||||
EmbedBuilder,
|
||||
InteractionResponse,
|
||||
SlashCommandSubcommandsOnlyBuilder,
|
||||
Attachment
|
||||
} from 'discord.js';
|
||||
import { HydratedDocument } from 'mongoose';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import axios from 'axios';
|
||||
import { Client } from 'minio';
|
||||
|
||||
import { Command } from '../../classes/command';
|
||||
import { logger } from '../../logger';
|
||||
import { config } from '../../config';
|
||||
import { reactPreprocess } from '../../functions/react-preprocess';
|
||||
import { Image, imageModel } from '../../models/Image';
|
||||
import { Alias, aliasModel } from '../../models/Alias';
|
||||
import { Guild, guildModel } from '../../models/Guild';
|
||||
import { Token, tokenModel } from '../../models/Token';
|
||||
|
||||
type CIOR = CommandInteractionOptionResolver;
|
||||
|
||||
const client = new Client(config.minio.client);
|
||||
|
||||
async function download(url: string, file: string): Promise<void>{
|
||||
const saveFile = await axios({
|
||||
url: url, method: 'GET', responseType: 'arraybuffer'
|
||||
});
|
||||
if(!await client.bucketExists(config.minio.bucket))
|
||||
await client.makeBucket(config.minio.bucket);
|
||||
|
||||
await client.putObject(config.minio.bucket, file, saveFile.data);
|
||||
}
|
||||
|
||||
async function upload(interaction: CommandInteraction): Promise<void>{
|
||||
if(!interaction.guildId)
|
||||
throw Error('guildId not exist');
|
||||
const file: discord.Attachment | null =
|
||||
(interaction.options as CIOR).getAttachment('file');
|
||||
if(!file)
|
||||
throw Error('file not exist');
|
||||
const fileExt: string = path.extname(file.name);
|
||||
|
||||
const image: HydratedDocument<Image> | null =
|
||||
await (new imageModel({extension: fileExt})).save();
|
||||
if(!image)
|
||||
throw Error('image not exist');
|
||||
await download(file.url, `${String(image._id)}${fileExt}`);
|
||||
|
||||
const publicUrl: string = `${config.httpServer.external.url}/${String(image._id)}${fileExt}`;
|
||||
await interaction.reply({
|
||||
content: logger.log(`Image saved with id: ${image._id}.`),
|
||||
});
|
||||
if(interaction.channel)
|
||||
await interaction.channel.send({content: publicUrl});
|
||||
}
|
||||
|
||||
async function link(interaction: CommandInteraction): Promise<void>{
|
||||
if(!interaction.guildId)
|
||||
throw Error('guildId not exist');
|
||||
let aliasText: string | null =
|
||||
(interaction.options as CIOR).getString('alias');
|
||||
if(!aliasText)
|
||||
throw Error('aliasText not exist');
|
||||
const imageId: string | null =
|
||||
(interaction.options as CIOR).getString('image');
|
||||
if(!imageId)
|
||||
throw Error('imageId not exist');
|
||||
|
||||
aliasText = reactPreprocess(aliasText);
|
||||
if(!interaction.guild || !interaction.guild.id || !interaction.guild.name)
|
||||
throw Error('guild not exist');
|
||||
const guild: HydratedDocument<Guild> | null =
|
||||
await guildModel.findOneAndUpdate(
|
||||
{id: interaction.guild.id},
|
||||
{$set: {name: interaction.guild.name}},
|
||||
{new: true, upsert: true}
|
||||
);
|
||||
if(!guild)
|
||||
throw Error('guild not exist');
|
||||
const image: HydratedDocument<Image> | null =
|
||||
await imageModel.findById(imageId);
|
||||
if(!image)
|
||||
throw Error('image not exist');
|
||||
const alias: HydratedDocument<Alias> | null =
|
||||
await aliasModel.findOneAndUpdate(
|
||||
{guild: guild, text: aliasText, images: {$nin: image}},
|
||||
{$push: {images: image}},
|
||||
{new: true, upsert: true}
|
||||
);
|
||||
if(!alias)
|
||||
throw Error('alias update failed');
|
||||
|
||||
await interaction.reply({
|
||||
content: logger.log(`Alias ${aliasText} has linked to image id: ${imageId}.`)
|
||||
});
|
||||
}
|
||||
|
||||
async function unlink(interaction: CommandInteraction): Promise<void>{
|
||||
if(!interaction.guildId)
|
||||
throw Error('guildId not exist');
|
||||
let aliasText: string | null =
|
||||
(interaction.options as CIOR).getString('alias');
|
||||
if(!aliasText)
|
||||
throw Error('aliasText not exist');
|
||||
aliasText = reactPreprocess(aliasText);
|
||||
if(!interaction.guild || !interaction.guild.id)
|
||||
throw Error('guild not exist');
|
||||
const guild: HydratedDocument<Guild> | null =
|
||||
await guildModel.findOne({id: interaction.guild.id});
|
||||
if(!guild)
|
||||
throw Error('guild not exist');
|
||||
const res = await aliasModel.deleteOne(
|
||||
{guild: guild, text: aliasText}
|
||||
);
|
||||
if(!res)
|
||||
logger.warning('alias not exist');
|
||||
|
||||
await interaction.reply({
|
||||
content: logger.log(`All the image have been unlinked to alias ${aliasText}.`)
|
||||
});
|
||||
}
|
||||
|
||||
async function list(interaction: CommandInteraction): Promise<void>{
|
||||
const token: string = String(Math.floor(Math.random() * 100000000));
|
||||
if(!interaction.guild || !interaction.guild.id)
|
||||
throw Error('guild not exist');
|
||||
await tokenModel.create({
|
||||
token: token,
|
||||
guildId: interaction.guild.id,
|
||||
exp: Date.now() + config.tokenTimeLimit
|
||||
});
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(0x1f1e33)
|
||||
.setTitle('Autoreact Image List')
|
||||
.setDescription('experimental function')
|
||||
.addFields({
|
||||
name: 'One Time Link:',
|
||||
value: `[open in browser](https://amane.konchin.com/auth?token=${token})`
|
||||
});
|
||||
await interaction.reply({embeds: [embed], ephemeral: true});
|
||||
}
|
||||
|
||||
class ImageCmd extends Command{
|
||||
get name(){return "image";}
|
||||
get description(){return "Modify the reacting image database.";}
|
||||
async execute(interaction: CommandInteraction): Promise<void>{
|
||||
try{
|
||||
const subcommand: string | null =
|
||||
(interaction.options as CIOR).getSubcommand();
|
||||
switch(subcommand){
|
||||
case 'upload':
|
||||
await upload(interaction); break;
|
||||
case 'link':
|
||||
await link(interaction); break;
|
||||
case 'unlink':
|
||||
await unlink(interaction); break;
|
||||
case 'list':
|
||||
await list(interaction); break;
|
||||
default:
|
||||
throw Error('subcommand not exist');
|
||||
}
|
||||
}catch(err: unknown){
|
||||
let message;
|
||||
if(err instanceof Error) message = err.message;
|
||||
else message = String(message);
|
||||
logger.error(`While executing "/image", ${message}`);
|
||||
await interaction.reply({content: `While executing "/image", ${message}`});
|
||||
}
|
||||
}
|
||||
override build(): SlashCommandSubcommandsOnlyBuilder{
|
||||
return new SlashCommandBuilder()
|
||||
.setName(this.name)
|
||||
.setDescription(this.description)
|
||||
.addSubcommand((subcommand: SlashCommandSubcommandBuilder) => subcommand
|
||||
.setName('upload')
|
||||
.setDescription('Upload an image.')
|
||||
.addAttachmentOption((option: SlashCommandAttachmentOption) => option
|
||||
.setName('file')
|
||||
.setDescription('The image file that you want to upload.')
|
||||
.setRequired(true)
|
||||
)
|
||||
)
|
||||
.addSubcommand((subcommand: SlashCommandSubcommandBuilder) => subcommand
|
||||
.setName('link')
|
||||
.setDescription('Link an alias to an image')
|
||||
.addStringOption((option: SlashCommandStringOption) => option
|
||||
.setName('alias')
|
||||
.setDescription('The alias to be linked.')
|
||||
.setRequired(true)
|
||||
)
|
||||
.addStringOption((option: SlashCommandStringOption) => option
|
||||
.setName('image')
|
||||
.setDescription('The image to be linked, as id.')
|
||||
.setRequired(true)
|
||||
)
|
||||
)
|
||||
.addSubcommand((subcommand: SlashCommandSubcommandBuilder) => subcommand
|
||||
.setName('unlink')
|
||||
.setDescription('Unlink an alias to an image')
|
||||
.addStringOption((option: SlashCommandStringOption) => option
|
||||
.setName('alias')
|
||||
.setDescription('The alias to be unlinked.')
|
||||
.setRequired(true)
|
||||
)
|
||||
)
|
||||
.addSubcommand((subcommand: SlashCommandSubcommandBuilder) => subcommand
|
||||
.setName('list')
|
||||
.setDescription('Show the image list')
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
export const command = new ImageCmd();
|
||||
@@ -1,90 +0,0 @@
|
||||
import discord, {
|
||||
CommandInteraction,
|
||||
CommandInteractionOptionResolver,
|
||||
SlashCommandBuilder,
|
||||
SlashCommandRoleOption,
|
||||
SlashCommandStringOption,
|
||||
InteractionResponse,
|
||||
} from 'discord.js';
|
||||
import {HydratedDocument} from 'mongoose';
|
||||
|
||||
import {Command} from '../../classes/command';
|
||||
import {logger} from '../../logger';
|
||||
import {AutoroleMsg, autoroleMsgModel} from '../../models/AutoroleMsg';
|
||||
import {Guild, guildModel} from '../../models/Guild';
|
||||
|
||||
type CIOR = CommandInteractionOptionResolver;
|
||||
|
||||
class Autorole extends Command{
|
||||
get name(){return "autorole";}
|
||||
get description(){return "Setup a autorole message.";}
|
||||
async execute(interaction: CommandInteraction): Promise<void>{
|
||||
try{
|
||||
let role = (interaction.options as CIOR).getRole('role');
|
||||
if(!role)
|
||||
throw Error('role not exist');
|
||||
const title: string | null =
|
||||
(interaction.options as CIOR).getString('title');
|
||||
if(!title)
|
||||
throw Error('title not exist');
|
||||
const message: string | null =
|
||||
(interaction.options as CIOR).getString('message');
|
||||
if(!message)
|
||||
throw Error('message not exist');
|
||||
|
||||
if(!interaction.guild || !interaction.guild.id || !interaction.guild.name)
|
||||
throw Error('guildId not exist');
|
||||
if(!interaction.channelId)
|
||||
throw Error('channelId not exist');
|
||||
let content: string = `>> **Auto Role: ${title}** <<\n`;
|
||||
content += '*React to give yourself a role.*\n\n';
|
||||
content += `${message}`;
|
||||
let msg: discord.Message =
|
||||
await (await interaction.reply({content: content})).fetch();
|
||||
const guild: HydratedDocument<Guild> | null =
|
||||
await guildModel.findOneAndUpdate(
|
||||
{id: interaction.guild.id},
|
||||
{$set: {name: interaction.guild.name}},
|
||||
{upsert: true, new: true}
|
||||
);
|
||||
if(!guild)
|
||||
throw Error('guild not exist');
|
||||
const autoroleMsg: HydratedDocument<AutoroleMsg> | null =
|
||||
await autoroleMsgModel.findOneAndUpdate(
|
||||
{guild: guild, messageId: msg.id, roleId: role.id},
|
||||
{}, {upsert: true, new: true}
|
||||
);
|
||||
if(!autoroleMsg)
|
||||
throw Error('autoroleMsg not exist');
|
||||
}catch(err: unknown){
|
||||
let message;
|
||||
if(err instanceof Error) message = err.message;
|
||||
else message = String(message);
|
||||
logger.error(`While executing "/autorole", ${message}`);
|
||||
await interaction.reply({content: `While executing "/autorole", ${message}`});
|
||||
}
|
||||
}
|
||||
override build(): SlashCommandBuilder |
|
||||
Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup">{
|
||||
return new SlashCommandBuilder()
|
||||
.setName(this.name)
|
||||
.setDescription(this.description)
|
||||
.addRoleOption((option: SlashCommandRoleOption) => option
|
||||
.setName('role')
|
||||
.setDescription('The role that autorole gives when reacted.')
|
||||
.setRequired(true)
|
||||
)
|
||||
.addStringOption((option: SlashCommandStringOption) => option
|
||||
.setName('title')
|
||||
.setDescription('The title displayed with the autorole message.')
|
||||
.setRequired(true)
|
||||
)
|
||||
.addStringOption((option: SlashCommandStringOption) => option
|
||||
.setName('message')
|
||||
.setDescription('The additional message displayed with the autorole message.')
|
||||
.setRequired(true)
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
export const command = new Autorole();
|
||||
@@ -1,10 +0,0 @@
|
||||
import {CommandInteraction} from 'discord.js';
|
||||
import {Command} from '../../classes/command';
|
||||
|
||||
class Test extends Command{
|
||||
get name(){return "test";}
|
||||
get description(){return "Testing some features.";}
|
||||
async execute(interaction: CommandInteraction): Promise<void>{}
|
||||
};
|
||||
|
||||
// export const command = new Test();
|
||||
@@ -1,29 +0,0 @@
|
||||
import {CommandInteraction, EmbedBuilder} from 'discord.js';
|
||||
|
||||
import {Command} from '../../classes/command';
|
||||
import {logger} from '../../logger';
|
||||
import {config} from '../../config';
|
||||
|
||||
class Help extends Command{
|
||||
get name(){return "help";}
|
||||
get description(){return "Help messages.";}
|
||||
async execute(interaction: CommandInteraction): Promise<void>{
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle("Help message")
|
||||
.setDescription(`Report issues on [this page](${config.urls.issue})`)
|
||||
.setColor(0x1f1e33)
|
||||
.setAuthor({
|
||||
name: 'Ian Shih (konchin)',
|
||||
url: config.urls.author,
|
||||
iconURL: config.urls.icon
|
||||
})
|
||||
.setFields(
|
||||
{name: 'Read the documentation', value: config.urls.help},
|
||||
{name: 'Read the source code', value: config.urls.git}
|
||||
);
|
||||
await interaction.reply({embeds: [embed], ephemeral: true});
|
||||
logger.log(`Command: help`);
|
||||
}
|
||||
};
|
||||
|
||||
export const command = new Help();
|
||||
@@ -1,19 +0,0 @@
|
||||
import {CommandInteraction} from 'discord.js';
|
||||
import {Command} from '../../classes/command';
|
||||
|
||||
class Ping extends Command{
|
||||
get name(){return "ping";}
|
||||
get description(){return "Reply with the RTT of this bot.";}
|
||||
async execute(interaction: CommandInteraction): Promise<void>{
|
||||
const sent = await interaction.reply({
|
||||
content: "Pinging...",
|
||||
ephemeral: true,
|
||||
fetchReply: true,
|
||||
});
|
||||
await interaction.editReply(`Roundtrip latency: ${
|
||||
sent.createdTimestamp - interaction.createdTimestamp
|
||||
}ms`);
|
||||
}
|
||||
};
|
||||
|
||||
export const command = new Ping();
|
||||
@@ -1,104 +0,0 @@
|
||||
import discord, {
|
||||
CommandInteraction,
|
||||
CommandInteractionOptionResolver,
|
||||
SlashCommandBuilder,
|
||||
SlashCommandSubcommandBuilder,
|
||||
SlashCommandStringOption,
|
||||
SlashCommandChannelOption,
|
||||
InteractionResponse,
|
||||
SlashCommandSubcommandsOnlyBuilder,
|
||||
} from 'discord.js';
|
||||
import {HydratedDocument} from 'mongoose';
|
||||
|
||||
import {Command} from '../../classes/command';
|
||||
import {logger} from '../../logger';
|
||||
import {Guild, guildModel} from '../../models/Guild';
|
||||
|
||||
type CIOR = CommandInteractionOptionResolver;
|
||||
|
||||
async function log(interaction: CommandInteraction): Promise<void>{
|
||||
const feature: string | null =
|
||||
(interaction.options as CIOR).getString('feature');
|
||||
if(!feature)
|
||||
throw Error('feature not exist');
|
||||
const logChannel = (interaction.options as CIOR).getChannel('channel');
|
||||
if(!logChannel || !('send' in logChannel))
|
||||
throw Error('logChannel not exist or illegal');
|
||||
if(!interaction.guild || !interaction.guild.id || !interaction.guild.name)
|
||||
throw Error('guild not exist');
|
||||
let guild: HydratedDocument<Guild> | null = null;
|
||||
switch(feature){
|
||||
case 'giveaway':
|
||||
await guildModel.findOneAndUpdate(
|
||||
{id: interaction.guild.id},
|
||||
{$set: {
|
||||
name: interaction.guild.name,
|
||||
giveawayLogChannelId: logChannel.id
|
||||
}},
|
||||
{new: true, upsert: true}
|
||||
);
|
||||
break;
|
||||
case 'autorole':
|
||||
await guildModel.findOneAndUpdate(
|
||||
{id: interaction.guild.id},
|
||||
{$set: {
|
||||
name: interaction.guild.name,
|
||||
autoroleLogChannelId: logChannel.id
|
||||
}},
|
||||
{new: true, upsert: true}
|
||||
);
|
||||
break;
|
||||
}
|
||||
await interaction.reply({
|
||||
content: logger.log(`The log channel of ${feature} has been set to ${logChannel}`)
|
||||
});
|
||||
;
|
||||
}
|
||||
|
||||
class SetVariables extends Command{
|
||||
get name(){return "set";}
|
||||
get description(){return "Set guild variables.";}
|
||||
async execute(interaction: CommandInteraction): Promise<void>{
|
||||
try{
|
||||
const subcommand: string =
|
||||
(interaction.options as CIOR).getSubcommand();
|
||||
switch(subcommand){
|
||||
case 'log':
|
||||
await log(interaction); break;
|
||||
default:
|
||||
throw Error('subcommand not exist');
|
||||
}
|
||||
}catch(err: unknown){
|
||||
let message;
|
||||
if(err instanceof Error) message = err.message;
|
||||
else message = String(message);
|
||||
logger.error(`While executing "/set", ${message}`);
|
||||
await interaction.reply({content: `While executing "/set", ${message}`});
|
||||
}
|
||||
}
|
||||
override build(): SlashCommandSubcommandsOnlyBuilder{
|
||||
return new SlashCommandBuilder()
|
||||
.setName(this.name)
|
||||
.setDescription(this.description)
|
||||
.addSubcommand((subcommand: SlashCommandSubcommandBuilder) => subcommand
|
||||
.setName('log')
|
||||
.setDescription('Set log of features.')
|
||||
.addStringOption((option: SlashCommandStringOption) => option
|
||||
.setName('feature')
|
||||
.setDescription('Specify the to be set feature.')
|
||||
.setRequired(true)
|
||||
.addChoices(
|
||||
{name: 'giveaway', value: 'giveaway'},
|
||||
{name: 'autorole', value: 'autorole'},
|
||||
)
|
||||
)
|
||||
.addChannelOption((option: SlashCommandChannelOption) => option
|
||||
.setName('channel')
|
||||
.setDescription('The channel that log send to.')
|
||||
.setRequired(true)
|
||||
)
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
export const command = new SetVariables();
|
||||
@@ -1,51 +0,0 @@
|
||||
import dotenv from 'dotenv';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
export const config = {
|
||||
token: process.env.DC_TOKEN!,
|
||||
clientId: process.env.DC_CLIENTID!,
|
||||
adminId: process.env.ADMIN_ID ?? '',
|
||||
nickname: '谷風 天音',
|
||||
data: '.',
|
||||
urls: {
|
||||
author: 'https://hello.konchin.com',
|
||||
icon: 'https://secure.gravatar.com/avatar/c35f2cb664f366e3e3365b9c22216834?d=identicon&s=512',
|
||||
help: 'https://md.konchin.com/s/u7qUK4oY4',
|
||||
git: 'https://git.konchin.com/discord-bot/Tanikaze-Amane',
|
||||
issue: 'https://git.konchin.com/discord-bot/Tanikaze-Amane/issues'
|
||||
},
|
||||
giveaway: {
|
||||
emoji: '✋',
|
||||
},
|
||||
logger: {
|
||||
logFile: 'test.log',
|
||||
},
|
||||
httpServer: {
|
||||
local: {
|
||||
port: process.env.PORT ?? 8082,
|
||||
},
|
||||
external: {
|
||||
url: 'https://amane.konchin.com/img'
|
||||
},
|
||||
},
|
||||
mongodb: {
|
||||
host: process.env.MONGODB_HOST ?? '127.0.0.1',
|
||||
port: process.env.MONGODB_PORT ?? 27017,
|
||||
db: process.env.MONGODB_DB ?? 'amanev2',
|
||||
user: process.env.MONGODB_USER ?? 'amane',
|
||||
pass: process.env.MONGODB_PASS!,
|
||||
reset: process.env.DB_RESET ?? 'false',
|
||||
},
|
||||
tokenTimeLimit: 60 * 1000,
|
||||
minio: {
|
||||
bucket: 'amane-img',
|
||||
client: {
|
||||
endPoint: process.env.MINIO_ENDPOINT ?? 'minio.konchin.com',
|
||||
useSSL: (process.env.MINIO_USESSL == 'true') ?? false,
|
||||
port: (process.env.MINIO_PORT as unknown as number) ?? 9000,
|
||||
accessKey: process.env.MINIO_ACCESSKEY ?? '',
|
||||
secretKey: process.env.MINIO_SECRETKEY ?? '',
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
---
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:17.2
|
||||
environment:
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: poop
|
||||
ports:
|
||||
- 5432:5432
|
||||
volumes:
|
||||
- ./docker/postgres/:/docker-entrypoint-initdb.d/
|
||||
- postgres:/var/lib/postgresql/data
|
||||
restart: unless-stopped
|
||||
|
||||
minio:
|
||||
image: minio/minio:RELEASE.2025-07-23T15-54-02Z
|
||||
environment:
|
||||
MINIO_ROOT_USER: poop
|
||||
MINIO_ROOT_PASSWORD: poop1145141919810
|
||||
command: ["server", "/data", "--console-address", ":9001"]
|
||||
ports:
|
||||
- 9000:9000
|
||||
- 9001:9001
|
||||
volumes:
|
||||
- minio:/data
|
||||
restart: unless-stopped
|
||||
|
||||
backend:
|
||||
build:
|
||||
context: .
|
||||
env_file:
|
||||
- path: .env
|
||||
command:
|
||||
- backend
|
||||
ports:
|
||||
- 8080:8080
|
||||
depends_on:
|
||||
- postgres
|
||||
- minio
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
redis: {}
|
||||
postgres: {}
|
||||
minio: {}
|
||||
@@ -0,0 +1,4 @@
|
||||
CREATE USER amane;
|
||||
CREATE DATABASE amane;
|
||||
ALTER DATABASE amane OWNER TO amane;
|
||||
ALTER USER amane ENCRYPTED PASSWORD 'amane';
|
||||
@@ -1,101 +0,0 @@
|
||||
import discord, {
|
||||
MessageReaction, PartialMessageReaction,
|
||||
User, PartialUser,
|
||||
} from 'discord.js';
|
||||
import {HydratedDocument} from 'mongoose';
|
||||
|
||||
import {logger} from '../logger';
|
||||
import {config} from '../config';
|
||||
import {Guild, guildModel} from '../models/Guild';
|
||||
import {AutoroleMsg, autoroleMsgModel} from '../models/AutoroleMsg';
|
||||
|
||||
function isMessageReaction(reaction: MessageReaction | PartialMessageReaction): reaction is MessageReaction{
|
||||
return reaction.partial === false;
|
||||
}
|
||||
|
||||
function isUser(user: User | PartialUser): user is User{
|
||||
return user.partial === false;
|
||||
}
|
||||
|
||||
async function handleRole(
|
||||
reaction: MessageReaction | PartialMessageReaction,
|
||||
user: User | PartialUser,
|
||||
action: string
|
||||
): Promise<void>{
|
||||
try{
|
||||
if(config.clientId === user.id) return;
|
||||
if(reaction.partial)
|
||||
reaction = await reaction.fetch();
|
||||
if(user.partial)
|
||||
user = await user.fetch();
|
||||
|
||||
if(!isMessageReaction(reaction))
|
||||
throw Error('type mismatch: reaction.partial');
|
||||
if(!isUser(user))
|
||||
throw Error('type mismatch: user.partial');
|
||||
if(!reaction.emoji)
|
||||
throw Error('reaction.emoji not exist');
|
||||
const dbAutoroleMsg: HydratedDocument<AutoroleMsg> | null =
|
||||
await autoroleMsgModel.findOneAndUpdate(
|
||||
{messageId: reaction.message.id},
|
||||
{$set: {emoji: reaction.emoji.toString()}},
|
||||
{new: true}
|
||||
);
|
||||
if(!dbAutoroleMsg || dbAutoroleMsg.emoji !== reaction.emoji.toString())
|
||||
return;
|
||||
if(!reaction.me)
|
||||
await reaction.react();
|
||||
|
||||
const dbGuild: HydratedDocument<Guild> | null =
|
||||
await guildModel.findById(dbAutoroleMsg.guild._id);
|
||||
if(!dbGuild)
|
||||
throw Error('dbGuild not exist');
|
||||
|
||||
const guild: discord.Guild | null =
|
||||
await reaction.client.guilds.resolve(dbGuild.id);
|
||||
if(!guild)
|
||||
throw Error('guild not exist');
|
||||
|
||||
const role: discord.Role | null =
|
||||
await guild.roles.resolve(dbAutoroleMsg.roleId);
|
||||
if(!role)
|
||||
throw Error('role not exist');
|
||||
|
||||
switch(action){
|
||||
case 'add': await guild.members.addRole({
|
||||
user: user.id, role: role.id
|
||||
}); break;
|
||||
case 'remove': await guild.members.removeRole({
|
||||
user: user.id, role: role.id
|
||||
}); break;
|
||||
}
|
||||
|
||||
logger.log(`${user} has been ${action === 'add'?'given':'removed'} ${role} role.`);
|
||||
if('autoroleLogChannelId' in dbGuild && dbGuild.autoroleLogChannelId){
|
||||
const autoroleChannel: discord.Channel | null =
|
||||
await guild.channels.resolve(dbGuild.autoroleLogChannelId);
|
||||
if(autoroleChannel === null || !autoroleChannel.isTextBased())
|
||||
throw Error('autoroleChannel not exist or autoroleChannel isn\'t text based');
|
||||
await autoroleChannel.send({content:
|
||||
`${user} has been ${action === 'add'?'given':'removed'} ${role} role.`
|
||||
});
|
||||
}
|
||||
}catch(err: unknown){
|
||||
let message;
|
||||
if(err instanceof Error) message = err.message;
|
||||
else message = String(message);
|
||||
logger.error(`While executing "handle-autorole", ${message}`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function handleRoleAdd(
|
||||
reaction: MessageReaction | PartialMessageReaction, user: User | PartialUser
|
||||
): Promise<void>{
|
||||
await handleRole(reaction, user, 'add');
|
||||
}
|
||||
|
||||
export async function handleRoleRemove(
|
||||
reaction: MessageReaction | PartialMessageReaction, user: User | PartialUser
|
||||
): Promise<void>{
|
||||
await handleRole(reaction, user, 'remove');
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
import {Interaction} from 'discord.js';
|
||||
|
||||
import {isExtendedClient} from '../classes/extendedclient';
|
||||
import {logger} from '../logger';
|
||||
|
||||
export async function handleCommands(interaction: Interaction): Promise<void>{
|
||||
if(!interaction.isChatInputCommand()) return;
|
||||
if(interaction.commandName === null)
|
||||
throw logger.error('interaction.commandName not exist');
|
||||
if(!isExtendedClient(interaction.client))
|
||||
throw logger.error(`Type Error in function "handleCommands"`);
|
||||
|
||||
const command = interaction.client.commands.get(interaction.commandName);
|
||||
if(!command)
|
||||
throw logger.error(`No command matching ${interaction.commandName} was found.`);
|
||||
|
||||
try{
|
||||
if('execute' in command)
|
||||
await command.execute(interaction);
|
||||
else{
|
||||
logger.error(`The command (${interaction.commandName}) is missing a require "execute" function`);
|
||||
return;
|
||||
}
|
||||
}catch(err: unknown){
|
||||
if(interaction.replied || interaction.deferred)
|
||||
await interaction.followUp({content: 'There was an error while executing this command!', ephemeral: true});
|
||||
else
|
||||
await interaction.reply({content: 'There was an error while executing this command!', ephemeral: true});
|
||||
throw logger.error(`While handling "${interaction.commandName}, ${err}"`);
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
import discord, {
|
||||
MessageReaction, PartialMessageReaction,
|
||||
User, PartialUser,
|
||||
} from 'discord.js';
|
||||
import {HydratedDocument} from 'mongoose';
|
||||
|
||||
import {logger} from '../logger';
|
||||
import {config} from '../config';
|
||||
import {Guild, guildModel} from '../models/Guild';
|
||||
import {GiveawayMsg, giveawayMsgModel} from '../models/GiveawayMsg';
|
||||
|
||||
function isMessageReaction(reaction: MessageReaction | PartialMessageReaction): reaction is MessageReaction{
|
||||
return reaction.partial === false;
|
||||
}
|
||||
|
||||
function isUser(user: User | PartialUser): user is User{
|
||||
return user.partial === false;
|
||||
}
|
||||
|
||||
export async function handleGiveaway(
|
||||
reaction: MessageReaction | PartialMessageReaction,
|
||||
user: User | PartialUser
|
||||
): Promise<void>{
|
||||
try{
|
||||
// fetch data
|
||||
if(config.clientId === user.id) return;
|
||||
if(reaction.partial){
|
||||
reaction = await reaction.fetch();
|
||||
logger.debug('reaction in handleRole has fetched');
|
||||
}
|
||||
if(user.partial){
|
||||
user = await user.fetch();
|
||||
logger.debug('user in handleRole has fetched');
|
||||
}
|
||||
if(!isMessageReaction(reaction))
|
||||
throw Error('type mismatch: reaction.partial');
|
||||
if(!isUser(user))
|
||||
throw Error('type mismatch: user.partial');
|
||||
if(!reaction.emoji)
|
||||
throw Error('reaction.emoji not exist');
|
||||
if(reaction.emoji.toString() !== config.giveaway.emoji) return;
|
||||
let dbGiveawayMsg: HydratedDocument<GiveawayMsg> | null =
|
||||
await giveawayMsgModel.findOne(
|
||||
{messageId: reaction.message.id}
|
||||
);
|
||||
if(!dbGiveawayMsg) return;
|
||||
if(dbGiveawayMsg.userIds.includes(user.id)){
|
||||
logger.info(`${user} has already in giveaway userIds`);
|
||||
return;
|
||||
}
|
||||
const dbGuild: HydratedDocument<Guild> | null =
|
||||
await guildModel.findById(dbGiveawayMsg.guild._id);
|
||||
if(!dbGuild)
|
||||
throw Error('dbGuild not exist');
|
||||
const guild: discord.Guild = await reaction.client.guilds.resolve(dbGuild.id);
|
||||
if(!guild)
|
||||
throw Error('guild not exist');
|
||||
|
||||
// record
|
||||
dbGiveawayMsg = await giveawayMsgModel.findOneAndUpdate(
|
||||
{messageId: dbGiveawayMsg.messageId},
|
||||
{$push: {userIds: user.id}}, {new: true}
|
||||
);
|
||||
if(!dbGiveawayMsg)
|
||||
throw Error('dbGiveawayMsg not exist');
|
||||
|
||||
// notify
|
||||
logger.log(`${user} has been reacted to giveaway, id: ${dbGiveawayMsg.messageId}.`);
|
||||
if(!dbGuild.giveawayLogChannelId){
|
||||
const author: discord.User | null =
|
||||
await reaction.client.users.fetch(dbGiveawayMsg.authorId);
|
||||
if(!author)
|
||||
throw Error(`author ${author} not exist`);
|
||||
await author.send({content: `user ${user} has reacted to giveaway, id: ${dbGiveawayMsg.messageId}`});
|
||||
}else{
|
||||
const logChannel: discord.Channel | null =
|
||||
await guild.channels.resolve(dbGuild.giveawayLogChannelId);
|
||||
if(!logChannel || !logChannel.isTextBased())
|
||||
throw Error('logChannel not exist or logChannel isn\'t text based');
|
||||
await logChannel.send({content: `user ${user} has reacted to giveaway, id: ${dbGiveawayMsg.messageId}`});
|
||||
}
|
||||
}catch(err: unknown){
|
||||
let message;
|
||||
if(err instanceof Error) message = err.message;
|
||||
else message = String(message);
|
||||
logger.error(`While executing "handleGiveaway", ${message}`);
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
import discord from 'discord.js';
|
||||
import {HydratedDocument} from 'mongoose';
|
||||
|
||||
import {logger} from '../logger';
|
||||
import {config} from '../config';
|
||||
import {reactPreprocess} from '../functions/react-preprocess';
|
||||
import {Alias, aliasModel} from '../models/Alias';
|
||||
import {Guild, guildModel} from '../models/Guild';
|
||||
import {Image, imageModel} from '../models/Image';
|
||||
|
||||
export async function handleReactImage(message: discord.Message): Promise<void>{
|
||||
try{
|
||||
if(!message.guild || !message.guild.id || !message.content) return;
|
||||
const guild: HydratedDocument<Guild> | null =
|
||||
await guildModel.findOne({id: message.guild.id});
|
||||
if(!guild) return; // not in guild
|
||||
const alias: HydratedDocument<Alias> | null =
|
||||
await aliasModel.findOne(
|
||||
{guild: guild, text: reactPreprocess(message.content)}
|
||||
);
|
||||
if(!alias) return; // alias not exist
|
||||
if(!alias.images.length) return; // alias not linked
|
||||
|
||||
const chosenImage: Image =
|
||||
alias.images[Math.floor(Math.random() * alias.images.length)];
|
||||
const image: HydratedDocument<Image> | null =
|
||||
await imageModel.findById(chosenImage._id);
|
||||
if(!image)
|
||||
throw Error('image not exist');
|
||||
|
||||
await message.channel.send({
|
||||
content: `${config.httpServer.external.url}/${image._id}${image.extension}`
|
||||
});
|
||||
}catch(err: unknown){
|
||||
let errMsg;
|
||||
if(err instanceof Error) errMsg = err.message;
|
||||
else errMsg = String(errMsg);
|
||||
logger.error(`While executing "handleReactImage", ${errMsg}`);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export function reactPreprocess(str: string){
|
||||
return str.toLowerCase().replaceAll(' ', '');
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
module gitea.konchin.com/service/amane-tanikaze-dcbot/amane
|
||||
|
||||
go 1.25.1
|
||||
|
||||
require (
|
||||
github.com/spf13/cobra v1.10.1
|
||||
github.com/spf13/viper v1.21.0
|
||||
github.com/swaggo/http-swagger v1.3.4
|
||||
github.com/swaggo/swag v1.16.2
|
||||
github.com/uptrace/bun v1.2.15
|
||||
github.com/uptrace/bun/dialect/pgdialect v1.2.15
|
||||
github.com/uptrace/bun/driver/pgdriver v1.2.15
|
||||
github.com/uptrace/bunrouter v1.0.23
|
||||
github.com/uptrace/opentelemetry-go-extra/otelzap v0.3.2
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0
|
||||
go.opentelemetry.io/otel v1.38.0
|
||||
go.opentelemetry.io/otel/trace v1.38.0
|
||||
go.uber.org/zap v1.27.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/KyleBanks/depth v1.2.1 // indirect
|
||||
github.com/fatih/color v1.18.0 // indirect
|
||||
github.com/felixge/httpsnoop v1.0.4 // indirect
|
||||
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
||||
github.com/go-logr/logr v1.4.3 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.19.6 // indirect
|
||||
github.com/go-openapi/jsonreference v0.20.2 // indirect
|
||||
github.com/go-openapi/spec v0.20.9 // indirect
|
||||
github.com/go-openapi/swag v0.22.3 // indirect
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/josharian/intern v1.0.0 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||
github.com/puzpuzpuz/xsync/v3 v3.5.1 // indirect
|
||||
github.com/sagikazarmark/locafero v0.11.0 // indirect
|
||||
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
|
||||
github.com/spf13/afero v1.15.0 // indirect
|
||||
github.com/spf13/cast v1.10.0 // indirect
|
||||
github.com/spf13/pflag v1.0.10 // indirect
|
||||
github.com/subosito/gotenv v1.6.0 // indirect
|
||||
github.com/swaggo/files v0.0.0-20220610200504-28940afbdbfe // indirect
|
||||
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
|
||||
github.com/uptrace/bun/extra/bundebug v1.2.15 // indirect
|
||||
github.com/uptrace/bun/extra/bunotel v1.2.15 // indirect
|
||||
github.com/uptrace/opentelemetry-go-extra/otelsql v0.3.2 // indirect
|
||||
github.com/uptrace/opentelemetry-go-extra/otelutil v0.3.2 // indirect
|
||||
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
|
||||
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
|
||||
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
|
||||
go.opentelemetry.io/otel/log v0.6.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.38.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.yaml.in/yaml/v3 v3.0.4 // indirect
|
||||
golang.org/x/crypto v0.40.0 // indirect
|
||||
golang.org/x/net v0.42.0 // indirect
|
||||
golang.org/x/sys v0.35.0 // indirect
|
||||
golang.org/x/text v0.28.0 // indirect
|
||||
golang.org/x/tools v0.35.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
mellium.im/sasl v0.3.2 // indirect
|
||||
)
|
||||
@@ -0,0 +1,188 @@
|
||||
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
|
||||
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
|
||||
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
|
||||
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
|
||||
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
||||
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
|
||||
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
|
||||
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
|
||||
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
|
||||
github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE=
|
||||
github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs=
|
||||
github.com/go-openapi/jsonreference v0.20.0/go.mod h1:Ag74Ico3lPc+zR+qjn4XBUmXymS4zJbYVCZmcgkasdo=
|
||||
github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE=
|
||||
github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k=
|
||||
github.com/go-openapi/spec v0.20.9 h1:xnlYNQAwKd2VQRRfwTEI0DcK+2cbuvI/0c7jx3gA8/8=
|
||||
github.com/go-openapi/spec v0.20.9/go.mod h1:2OpW+JddWPrpXSCIX8eOx7lZ5iyuWj3RYR6VaaBKcWA=
|
||||
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
|
||||
github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
|
||||
github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g=
|
||||
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
||||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
|
||||
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
|
||||
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
|
||||
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/puzpuzpuz/xsync/v3 v3.5.1 h1:GJYJZwO6IdxN/IKbneznS6yPkVC+c3zyY/j19c++5Fg=
|
||||
github.com/puzpuzpuz/xsync/v3 v3.5.1/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA=
|
||||
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
||||
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc=
|
||||
github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik=
|
||||
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw=
|
||||
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U=
|
||||
github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I=
|
||||
github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg=
|
||||
github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY=
|
||||
github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo=
|
||||
github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s=
|
||||
github.com/spf13/cobra v1.10.1/go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4XaB0=
|
||||
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
|
||||
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU=
|
||||
github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
|
||||
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
|
||||
github.com/swaggo/files v0.0.0-20220610200504-28940afbdbfe h1:K8pHPVoTgxFJt1lXuIzzOX7zZhZFldJQK/CgKx9BFIc=
|
||||
github.com/swaggo/files v0.0.0-20220610200504-28940afbdbfe/go.mod h1:lKJPbtWzJ9JhsTN1k1gZgleJWY/cqq0psdoMmaThG3w=
|
||||
github.com/swaggo/http-swagger v1.3.4 h1:q7t/XLx0n15H1Q9/tk3Y9L4n210XzJF5WtnDX64a5ww=
|
||||
github.com/swaggo/http-swagger v1.3.4/go.mod h1:9dAh0unqMBAlbp1uE2Uc2mQTxNMU/ha4UbucIg1MFkQ=
|
||||
github.com/swaggo/swag v1.16.2 h1:28Pp+8DkQoV+HLzLx8RGJZXNGKbFqnuvSbAAtoxiY04=
|
||||
github.com/swaggo/swag v1.16.2/go.mod h1:6YzXnDcpr0767iOejs318CwYkCQqyGer6BizOg03f+E=
|
||||
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc h1:9lRDQMhESg+zvGYmW5DyG0UqvY96Bu5QYsTLvCHdrgo=
|
||||
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc/go.mod h1:bciPuU6GHm1iF1pBvUfxfsH0Wmnc2VbpgvbI9ZWuIRs=
|
||||
github.com/uptrace/bun v1.2.15 h1:Ut68XRBLDgp9qG9QBMa9ELWaZOmzHNdczHQdrOZbEFE=
|
||||
github.com/uptrace/bun v1.2.15/go.mod h1:Eghz7NonZMiTX/Z6oKYytJ0oaMEJ/eq3kEV4vSqG038=
|
||||
github.com/uptrace/bun/dialect/pgdialect v1.2.15 h1:er+/3giAIqpfrXJw+KP9B7ujyQIi5XkPnFmgjAVL6bA=
|
||||
github.com/uptrace/bun/dialect/pgdialect v1.2.15/go.mod h1:QSiz6Qpy9wlGFsfpf7UMSL6mXAL1jDJhFwuOVacCnOQ=
|
||||
github.com/uptrace/bun/driver/pgdriver v1.2.15 h1:eZZ60ZtUUE6jjv6VAI1pCMaTgtx3sxmChQzwbvchOOo=
|
||||
github.com/uptrace/bun/driver/pgdriver v1.2.15/go.mod h1:s2zz/BAeScal4KLFDI8PURwATN8s9RDBsElEbnPAjv4=
|
||||
github.com/uptrace/bun/extra/bundebug v1.2.15 h1:IY2Z/pVyVg0ApWnQ/pEnwe6BWxlDDATCz7IFZghutCs=
|
||||
github.com/uptrace/bun/extra/bundebug v1.2.15/go.mod h1:JuE+BT7NjTZ9UKr74eC8s9yZ9dnQCeufDwFRTC8w3Xo=
|
||||
github.com/uptrace/bun/extra/bunotel v1.2.15 h1:6KAvKRpH9BC/7n3eMXVgDYLqghHf2H3FJOvxs/yjFJM=
|
||||
github.com/uptrace/bun/extra/bunotel v1.2.15/go.mod h1:qnASdcJVuoEE+13N3Gd8XHi5gwCydt2S1TccJnefH2k=
|
||||
github.com/uptrace/bunrouter v1.0.23 h1:Bi7NKw3uCQkcA/GUCtDNPq5LE5UdR9pe+UyWbjHB/wU=
|
||||
github.com/uptrace/bunrouter v1.0.23/go.mod h1:O3jAcl+5qgnF+ejhgkmbceEk0E/mqaK+ADOocdNpY8M=
|
||||
github.com/uptrace/opentelemetry-go-extra/otelsql v0.3.2 h1:ZjUj9BLYf9PEqBn8W/OapxhPjVRdC6CsXTdULHsyk5c=
|
||||
github.com/uptrace/opentelemetry-go-extra/otelsql v0.3.2/go.mod h1:O8bHQfyinKwTXKkiKNGmLQS7vRsqRxIQTFZpYpHK3IQ=
|
||||
github.com/uptrace/opentelemetry-go-extra/otelutil v0.3.2 h1:3/aHKUq7qaFMWxyQV0W2ryNgg8x8rVeKVA20KJUkfS0=
|
||||
github.com/uptrace/opentelemetry-go-extra/otelutil v0.3.2/go.mod h1:Zit4b8AQXaXvA68+nzmbyDzqiyFRISyw1JiD5JqUBjw=
|
||||
github.com/uptrace/opentelemetry-go-extra/otelzap v0.3.2 h1:cj/Z6FKTTYBnstI0Lni9PA+k2foounKIPUmj1LBwNiQ=
|
||||
github.com/uptrace/opentelemetry-go-extra/otelzap v0.3.2/go.mod h1:LDaXk90gKEC2nC7JH3Lpnhfu+2V7o/TsqomJJmqA39o=
|
||||
github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8=
|
||||
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
|
||||
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
|
||||
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
|
||||
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
||||
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0 h1:RbKq8BG0FI8OiXhBfcRtqqHcZcka+gU3cskNuf05R18=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0/go.mod h1:h06DGIukJOevXaj/xrNjhi/2098RZzcLTbc0jDAUbsg=
|
||||
go.opentelemetry.io/otel v1.38.0 h1:RkfdswUDRimDg0m2Az18RKOsnI8UDzppJAtj01/Ymk8=
|
||||
go.opentelemetry.io/otel v1.38.0/go.mod h1:zcmtmQ1+YmQM9wrNsTGV/q/uyusom3P8RxwExxkZhjM=
|
||||
go.opentelemetry.io/otel/log v0.6.0 h1:nH66tr+dmEgW5y+F9LanGJUBYPrRgP4g2EkmPE3LeK8=
|
||||
go.opentelemetry.io/otel/log v0.6.0/go.mod h1:KdySypjQHhP069JX0z/t26VHwa8vSwzgaKmXtIB3fJM=
|
||||
go.opentelemetry.io/otel/metric v1.38.0 h1:Kl6lzIYGAh5M159u9NgiRkmoMKjvbsKtYRwgfrA6WpA=
|
||||
go.opentelemetry.io/otel/metric v1.38.0/go.mod h1:kB5n/QoRM8YwmUahxvI3bO34eVtQf2i4utNVLr9gEmI=
|
||||
go.opentelemetry.io/otel/sdk v1.38.0 h1:l48sr5YbNf2hpCUj/FoGhW9yDkl+Ma+LrVl8qaM5b+E=
|
||||
go.opentelemetry.io/otel/sdk v1.38.0/go.mod h1:ghmNdGlVemJI3+ZB5iDEuk4bWA3GkTpW+DOoZMYBVVg=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.38.0 h1:aSH66iL0aZqo//xXzQLYozmWrXxyFkBJ6qT5wthqPoM=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.38.0/go.mod h1:dg9PBnW9XdQ1Hd6ZnRz689CbtrUp0wMMs9iPcgT9EZA=
|
||||
go.opentelemetry.io/otel/trace v1.38.0 h1:Fxk5bKrDZJUH+AMyyIXGcFAPah0oRcT+LuNtJrmcNLE=
|
||||
go.opentelemetry.io/otel/trace v1.38.0/go.mod h1:j1P9ivuFsTceSWe1oY+EeW3sc+Pp42sO++GHkg4wwhs=
|
||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
|
||||
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
|
||||
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
||||
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
|
||||
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||
golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
|
||||
golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
|
||||
golang.org/x/mod v0.26.0 h1:EGMPT//Ezu+ylkCijjPc+f4Aih7sZvaAr+O3EHBxvZg=
|
||||
golang.org/x/mod v0.26.0/go.mod h1:/j6NAhSk8iQ723BGAUyoAcn7SlD7s15Dp9Nd/SfeaFQ=
|
||||
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
|
||||
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
|
||||
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
|
||||
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
|
||||
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
|
||||
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.35.0 h1:mBffYraMEf7aa0sB+NuKnuCy8qI/9Bughn8dC2Gu5r0=
|
||||
golang.org/x/tools v0.35.0/go.mod h1:NKdj5HkL/73byiZSJjqJgKn3ep7KjFkBOkR/Hps3VPw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
mellium.im/sasl v0.3.2 h1:PT6Xp7ccn9XaXAnJ03FcEjmAn7kK1x7aoXV6F+Vmrl0=
|
||||
mellium.im/sasl v0.3.2/go.mod h1:NKXDi1zkr+BlMHLQjY3ofYuU4KSPFxknb8mfEu6SveY=
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.6 h1:XJtiaUW6dEEqVuZiMTn1ldk455QWwEIsMIJlo5vtkx0=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
github.com/santhosh-tekuri/jsonschema/v5 v5.2.0/go.mod h1:FKdcjfQW6rpZSnxxUvEA5H/cDPdvJ/SZJQLWWXWGrZ0=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
|
||||
github.com/urfave/cli/v2 v2.25.1 h1:zw8dSP7ghX0Gmm8vugrs6q9Ku0wzweqPyshy+syu9Gw=
|
||||
github.com/urfave/cli/v2 v2.25.1/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/telemetry v0.0.0-20250710130107-8d8967aff50b/go.mod h1:4ZwOYna0/zsOKwuR5X/m0QFOJpSZvAxFfkQT+Erd9D4=
|
||||
golang.org/x/term v0.33.0/go.mod h1:s18+ql9tYWp1IfpV9DmCtQDDSRBUjKaw9M1eAv5UeF0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
|
||||
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
|
||||
@@ -0,0 +1,15 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/uptrace/bunrouter"
|
||||
)
|
||||
|
||||
func (*Handlers) GetAliases(
|
||||
w http.ResponseWriter,
|
||||
req bunrouter.Request,
|
||||
) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"gitea.konchin.com/service/amane-tanikaze-dcbot/amane/middlewares"
|
||||
"gitea.konchin.com/service/amane-tanikaze-dcbot/amane/utils"
|
||||
"github.com/uptrace/bunrouter"
|
||||
)
|
||||
|
||||
// GetImage
|
||||
//
|
||||
// @Param id query string true "image id"
|
||||
// @Success 200
|
||||
// @Router /api/image [get]
|
||||
func (*Handlers) GetImage(
|
||||
w http.ResponseWriter,
|
||||
req bunrouter.Request,
|
||||
) error {
|
||||
imageId := req.URL.Query().Get("id")
|
||||
if imageId == "" {
|
||||
return middlewares.HTTPError{
|
||||
StatusCode: http.StatusBadRequest,
|
||||
Message: "must provide id",
|
||||
}
|
||||
}
|
||||
return utils.Success(w)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package api
|
||||
|
||||
import "github.com/uptrace/bun"
|
||||
|
||||
type Handlers struct {
|
||||
db *bun.DB
|
||||
}
|
||||
|
||||
func NewHandlers(db *bun.DB) *Handlers {
|
||||
return &Handlers{db: db}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
package api
|
||||
@@ -0,0 +1 @@
|
||||
package api
|
||||
@@ -0,0 +1 @@
|
||||
package auth
|
||||
@@ -0,0 +1,59 @@
|
||||
// Package docs Code generated by swaggo/swag. DO NOT EDIT
|
||||
package docs
|
||||
|
||||
import "github.com/swaggo/swag"
|
||||
|
||||
const docTemplate = `{
|
||||
"schemes": {{ marshal .Schemes }},
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"description": "{{escape .Description}}",
|
||||
"title": "{{.Title}}",
|
||||
"termsOfService": "http://swagger.io/terms/",
|
||||
"contact": {},
|
||||
"license": {
|
||||
"name": "0BSD"
|
||||
},
|
||||
"version": "{{.Version}}"
|
||||
},
|
||||
"host": "{{.Host}}",
|
||||
"basePath": "{{.BasePath}}",
|
||||
"paths": {
|
||||
"/api/image": {
|
||||
"get": {
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "image id",
|
||||
"name": "id",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
||||
// SwaggerInfo holds exported Swagger Info so clients can modify it
|
||||
var SwaggerInfo = &swag.Spec{
|
||||
Version: "2.0-alpha1",
|
||||
Host: "",
|
||||
BasePath: "/",
|
||||
Schemes: []string{},
|
||||
Title: "Amane Tanikaze Discord Bot Backend",
|
||||
Description: "",
|
||||
InfoInstanceName: "swagger",
|
||||
SwaggerTemplate: docTemplate,
|
||||
LeftDelim: "{{",
|
||||
RightDelim: "}}",
|
||||
}
|
||||
|
||||
func init() {
|
||||
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "Amane Tanikaze Discord Bot Backend",
|
||||
"termsOfService": "http://swagger.io/terms/",
|
||||
"contact": {},
|
||||
"license": {
|
||||
"name": "0BSD"
|
||||
},
|
||||
"version": "2.0-alpha1"
|
||||
},
|
||||
"basePath": "/",
|
||||
"paths": {
|
||||
"/api/image": {
|
||||
"get": {
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "image id",
|
||||
"name": "id",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
basePath: /
|
||||
info:
|
||||
contact: {}
|
||||
license:
|
||||
name: 0BSD
|
||||
termsOfService: http://swagger.io/terms/
|
||||
title: Amane Tanikaze Discord Bot Backend
|
||||
version: 2.0-alpha1
|
||||
paths:
|
||||
/api/image:
|
||||
get:
|
||||
parameters:
|
||||
- description: image id
|
||||
in: query
|
||||
name: id
|
||||
required: true
|
||||
type: string
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
swagger: "2.0"
|
||||
@@ -1,97 +0,0 @@
|
||||
import {Events, GatewayIntentBits, Partials, ActivityType} from 'discord.js';
|
||||
import {createServer} from 'http';
|
||||
|
||||
// Global config
|
||||
import {config} from './config';
|
||||
|
||||
// Classes
|
||||
import {ExtendedClient} from './classes/extendedclient'
|
||||
|
||||
// Initialization functions
|
||||
import {setNickname} from './init/set-nickname';
|
||||
import {loadCommands} from './init/load-commands';
|
||||
import {registerCommands} from './init/register-commands';
|
||||
import {sendReadyDM} from './init/ready-dm';
|
||||
|
||||
// Event-handling functions
|
||||
import {handleCommands} from './events/handle-commands';
|
||||
import {handleGiveaway} from './events/handle-giveaway';
|
||||
import {handleRoleAdd, handleRoleRemove} from './events/handle-auto-roles';
|
||||
import {handleReactImage} from './events/handle-react-image';
|
||||
|
||||
// Sub-services
|
||||
import {logger} from './logger';
|
||||
import {runMongo} from './mongo';
|
||||
|
||||
const client = new ExtendedClient({
|
||||
intents:[
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildMembers,
|
||||
GatewayIntentBits.GuildModeration,
|
||||
GatewayIntentBits.GuildEmojisAndStickers,
|
||||
GatewayIntentBits.GuildIntegrations,
|
||||
GatewayIntentBits.GuildWebhooks,
|
||||
GatewayIntentBits.GuildInvites,
|
||||
GatewayIntentBits.GuildVoiceStates,
|
||||
GatewayIntentBits.GuildPresences,
|
||||
GatewayIntentBits.GuildMessages,
|
||||
GatewayIntentBits.GuildMessageReactions,
|
||||
GatewayIntentBits.GuildMessageTyping,
|
||||
GatewayIntentBits.DirectMessages,
|
||||
GatewayIntentBits.DirectMessageReactions,
|
||||
GatewayIntentBits.DirectMessageTyping,
|
||||
GatewayIntentBits.MessageContent,
|
||||
GatewayIntentBits.GuildScheduledEvents,
|
||||
GatewayIntentBits.AutoModerationConfiguration,
|
||||
GatewayIntentBits.AutoModerationExecution,
|
||||
],
|
||||
partials:[
|
||||
Partials.User,
|
||||
Partials.Channel,
|
||||
Partials.GuildMember,
|
||||
Partials.Message,
|
||||
Partials.Reaction,
|
||||
Partials.GuildScheduledEvent,
|
||||
Partials.ThreadMember,
|
||||
]
|
||||
});
|
||||
|
||||
client.login(config.token);
|
||||
|
||||
// Event handling
|
||||
client.on(Events.InteractionCreate, handleCommands);
|
||||
client.on(Events.MessageReactionAdd, handleGiveaway);
|
||||
client.on(Events.MessageReactionAdd, handleRoleAdd);
|
||||
client.on(Events.MessageReactionRemove, handleRoleRemove);
|
||||
client.on(Events.MessageCreate, handleReactImage);
|
||||
|
||||
// Initialization
|
||||
client.once(Events.ClientReady, async c => {
|
||||
logger.info(`Logged in as ${c.user.tag}`);
|
||||
|
||||
if(client.user){
|
||||
client.user.setPresence({
|
||||
activities: [{
|
||||
name: '天使☆騒々 RE-BOOT!',
|
||||
type: ActivityType.Playing,
|
||||
}],
|
||||
status: 'online'
|
||||
});
|
||||
logger.info('Set status done');
|
||||
}
|
||||
|
||||
await setNickname(client);
|
||||
logger.info(`Set nickname as ${config.nickname}`);
|
||||
|
||||
const commands = await loadCommands(client);
|
||||
logger.info(`${commands.length} commands loaded.`);
|
||||
|
||||
const regCmdCnt = await registerCommands(commands);
|
||||
logger.info(`${regCmdCnt} commands registered.`);
|
||||
|
||||
await runMongo();
|
||||
logger.info(`Database ready`);
|
||||
|
||||
logger.info(`Ready!`);
|
||||
await sendReadyDM(client, config.adminId);
|
||||
});
|
||||
@@ -1,27 +0,0 @@
|
||||
import path from 'path';
|
||||
import { readdir } from 'node:fs/promises';
|
||||
|
||||
import { ExtendedClient } from '../classes/extendedclient';
|
||||
import { logger } from '../logger';
|
||||
|
||||
export async function loadCommands(client: ExtendedClient): Promise<Array<string>>{
|
||||
const foldersPath = path.join(__dirname, '../commands');
|
||||
const commandFolders = await readdir(foldersPath);
|
||||
const commands: Array<string> = [];
|
||||
for(const folder of commandFolders){
|
||||
const commandsPath = path.join(foldersPath, folder);
|
||||
const commandsFiles = path.basename(__filename).endsWith('.ts')
|
||||
? (await readdir(commandsPath)).filter(file => file.endsWith('.ts'))
|
||||
: (await readdir(commandsPath)).filter(file => file.endsWith('.js'));
|
||||
for(const file of commandsFiles){
|
||||
const filePath = path.join(commandsPath, file);
|
||||
const data = await import(filePath);
|
||||
if(data.command !== undefined){
|
||||
client.commands.set(data.command.name, data.command);
|
||||
commands.push(data.command.build().toJSON());
|
||||
}else
|
||||
logger.warning(`The command at ${filePath} is missing required properties.`);
|
||||
}
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import {logger} from '../logger';
|
||||
import {ExtendedClient} from '../classes/extendedclient';
|
||||
|
||||
export async function sendReadyDM(client: ExtendedClient, adminId: string): Promise<void>{
|
||||
try{
|
||||
await (await client.users.fetch(adminId)).send(`service up at ${new Date()}`);
|
||||
logger.log('Service up message sent');
|
||||
}catch(err: unknown){
|
||||
logger.warning('sendReadyDM failed.');
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
import {REST, Routes} from 'discord.js';
|
||||
|
||||
import {config} from '../config';
|
||||
import {logger} from '../logger';
|
||||
|
||||
function isArray<T>(data: unknown): data is Array<T>{
|
||||
return (data as Array<T>).length !== undefined;
|
||||
}
|
||||
|
||||
export async function registerCommands(commands: Array<string>): Promise<number>{
|
||||
const rest = new REST().setToken(config.token);
|
||||
try{
|
||||
const data = await rest.put(
|
||||
Routes.applicationCommands(config.clientId),
|
||||
{body: commands},
|
||||
);
|
||||
if(!isArray(data)) throw Error('Type error');
|
||||
return data.length;
|
||||
}catch(err: unknown){
|
||||
let message;
|
||||
if(err instanceof Error) message = err.message;
|
||||
else message = String(message);
|
||||
logger.error(`While executing "registerCommands", ${message}`);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import {Guild} from 'discord.js';
|
||||
|
||||
import {ExtendedClient} from '../classes/extendedclient';
|
||||
import {config} from '../config';
|
||||
import {logger} from '../logger';
|
||||
|
||||
export async function setNickname(client: ExtendedClient): Promise<void>{
|
||||
await client.guilds.cache.forEach(async (guild: Guild): Promise<void> => {
|
||||
try{
|
||||
// console.log(guild.members);
|
||||
const self = await guild.members.fetch({user: config.clientId, force: true});
|
||||
if(!self) throw Error('self not exist');
|
||||
await self.setNickname(config.nickname);
|
||||
logger.log(`Nickname had changed in guild: ${guild.name}`);
|
||||
}catch(err: unknown){
|
||||
let message;
|
||||
if(err instanceof Error) message = err.message;
|
||||
else message = String(message);
|
||||
logger.error(`While executing setNickname, ${message}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
import {appendFileSync} from 'fs';
|
||||
import moment from 'moment-timezone';
|
||||
|
||||
import {config} from './config';
|
||||
|
||||
enum LogLevel{
|
||||
ERROR = 'ERROR',
|
||||
WARNING = 'WARNING',
|
||||
DEBUG = 'DEBUG',
|
||||
LOG = 'LOG',
|
||||
INFO = 'INFO',
|
||||
}
|
||||
|
||||
class Logger{
|
||||
constructor(readonly logFile?: string){
|
||||
this.debug('logger initialized');
|
||||
}
|
||||
private currentTime(): string{
|
||||
return '[' + moment().tz('Asia/Taipei').format('YYYY/MM/DD hh:mm:ss') + ']';
|
||||
}
|
||||
private writeLog(content: string, logLevel: LogLevel): void{
|
||||
const line = `${this.currentTime()} ${logLevel}: ${content}`;
|
||||
console.log(line);
|
||||
if(this.logFile !== undefined){
|
||||
appendFileSync(this.logFile, line + '\n');
|
||||
}
|
||||
}
|
||||
error(content: string): Error{
|
||||
this.writeLog(content, LogLevel.ERROR); return Error(content);
|
||||
}
|
||||
warning(content: string): string{
|
||||
this.writeLog(content, LogLevel.WARNING); return content;
|
||||
}
|
||||
debug(content: string): string{
|
||||
this.writeLog(content, LogLevel.DEBUG); return content;
|
||||
}
|
||||
log(content: string): string{
|
||||
this.writeLog(content, LogLevel.LOG); return content;
|
||||
}
|
||||
info(content: string): string{
|
||||
this.writeLog(content, LogLevel.INFO); return content;
|
||||
}
|
||||
}
|
||||
|
||||
export const logger = new Logger(`${config.data}/${config.logger.logFile}`);
|
||||
@@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
import "gitea.konchin.com/service/amane-tanikaze-dcbot/amane/cmd"
|
||||
|
||||
func main() {
|
||||
cmd.RootCmd.Execute()
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"gitea.konchin.com/service/amane-tanikaze-dcbot/amane/tracing"
|
||||
"github.com/uptrace/bunrouter"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type HTTPError struct {
|
||||
StatusCode int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
OriginError error `json:"-"`
|
||||
}
|
||||
|
||||
func (e HTTPError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
func NewHTTPError(err error) HTTPError {
|
||||
return HTTPError{
|
||||
StatusCode: http.StatusInternalServerError,
|
||||
Message: "Internal server error with unknown reason",
|
||||
OriginError: err,
|
||||
}
|
||||
}
|
||||
|
||||
func (self *Handlers) ErrorHandler(
|
||||
next bunrouter.HandlerFunc,
|
||||
) bunrouter.HandlerFunc {
|
||||
return func(w http.ResponseWriter, req bunrouter.Request) error {
|
||||
err := next(w, req)
|
||||
ctx := req.Context()
|
||||
|
||||
var httpErr HTTPError
|
||||
switch err := err.(type) {
|
||||
case nil:
|
||||
return nil
|
||||
|
||||
case HTTPError:
|
||||
httpErr = err
|
||||
|
||||
default:
|
||||
tracing.Logger.Ctx(ctx).
|
||||
Error("unhandled error",
|
||||
zap.Error(err))
|
||||
httpErr = NewHTTPError(err)
|
||||
}
|
||||
|
||||
// https://opentelemetry.io/docs/specs/semconv/http/http-spans/#status
|
||||
span := trace.SpanFromContext(ctx)
|
||||
span.SetAttributes(
|
||||
attribute.Int("http.response.status_code", httpErr.StatusCode),
|
||||
)
|
||||
|
||||
if 500 <= httpErr.StatusCode && httpErr.StatusCode <= 599 {
|
||||
span.SetStatus(codes.Error, err.Error())
|
||||
if httpErr.OriginError == nil {
|
||||
tracing.Logger.Ctx(ctx).
|
||||
Error(httpErr.Message)
|
||||
} else {
|
||||
tracing.Logger.Ctx(ctx).
|
||||
Error(httpErr.Message,
|
||||
zap.Error(httpErr.OriginError))
|
||||
}
|
||||
} else {
|
||||
span.SetStatus(codes.Ok, "")
|
||||
if httpErr.OriginError == nil {
|
||||
tracing.Logger.Ctx(ctx).
|
||||
Warn(httpErr.Message)
|
||||
} else {
|
||||
tracing.Logger.Ctx(ctx).
|
||||
Warn(httpErr.Message,
|
||||
zap.Error(httpErr.OriginError))
|
||||
}
|
||||
}
|
||||
|
||||
w.WriteHeader(httpErr.StatusCode)
|
||||
_ = bunrouter.JSON(w, httpErr)
|
||||
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package middlewares
|
||||
|
||||
import "github.com/uptrace/bun"
|
||||
|
||||
type Handlers struct {
|
||||
db *bun.DB
|
||||
}
|
||||
|
||||
func NewHandlers(db *bun.DB) *Handlers {
|
||||
return &Handlers{db: db}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS "image";
|
||||
@@ -0,0 +1,4 @@
|
||||
CREATE TABLE "image" (
|
||||
id integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
|
||||
ext character varying NOT NULL
|
||||
);
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS "guild";
|
||||
@@ -0,0 +1,7 @@
|
||||
CREATE TABLE "guild" (
|
||||
id integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
|
||||
dc_id character varying UNIQUE,
|
||||
name character varying NOT NULL,
|
||||
|
||||
auto_role_log_chan_id character varying
|
||||
);
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS "alias";
|
||||
@@ -0,0 +1,7 @@
|
||||
CREATE TABLE "alias" (
|
||||
id integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
|
||||
guild_id integer,
|
||||
alias character varying,
|
||||
|
||||
UNIQUE (guild_id, alias)
|
||||
);
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS "auto_role_msg";
|
||||
@@ -0,0 +1,8 @@
|
||||
CREATE TABLE "auto_role_msg" (
|
||||
guild_id integer,
|
||||
message_id character varying,
|
||||
role_id character varying NOT NULL,
|
||||
emoji character varying,
|
||||
|
||||
PRIMARY KEY (guild_id, message_id)
|
||||
);
|
||||
@@ -0,0 +1,7 @@
|
||||
ALTER TABLE "alias" ADD CONSTRAINT "guild_id_fk"
|
||||
FOREIGN KEY (guild_id) REFERENCES "guild" (id) ON DELETE CASCADE;
|
||||
|
||||
--bun:split
|
||||
|
||||
ALTER TABLE "auto_role_msg" ADD CONSTRAINT "guild_id_fk"
|
||||
FOREIGN KEY (guild_id) REFERENCES "guild" (id) ON DELETE CASCADE;
|
||||
@@ -0,0 +1,18 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"embed"
|
||||
|
||||
"github.com/uptrace/bun/migrate"
|
||||
)
|
||||
|
||||
var Migrations = migrate.NewMigrations()
|
||||
|
||||
//go:embed *.sql
|
||||
var sqlMigrations embed.FS
|
||||
|
||||
func init() {
|
||||
if err := Migrations.Discover(sqlMigrations); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import {Schema, Types, model} from 'mongoose';
|
||||
|
||||
import {Image} from './Image';
|
||||
import {Guild} from './Guild';
|
||||
|
||||
export interface Alias{
|
||||
_id: Types.ObjectId;
|
||||
guild: Guild;
|
||||
text: string;
|
||||
images: Image[];
|
||||
}
|
||||
|
||||
const aliasSchema = new Schema<Alias>({
|
||||
guild: {type: Schema.Types.ObjectId, ref: 'Guild', required: true},
|
||||
text: {type: String, required: true},
|
||||
images: {type: [{type: Schema.Types.ObjectId, ref: 'Image'}], default: []},
|
||||
});
|
||||
|
||||
export const aliasModel = model<Alias>(
|
||||
'aliasModel', aliasSchema
|
||||
);
|
||||
@@ -1,22 +0,0 @@
|
||||
import {Schema, Types, model} from 'mongoose';
|
||||
|
||||
import {Guild} from './Guild';
|
||||
|
||||
export interface AutoroleMsg{
|
||||
_id: Types.ObjectId;
|
||||
guild: Guild;
|
||||
messageId: string;
|
||||
emoji: string;
|
||||
roleId: string;
|
||||
}
|
||||
|
||||
const autoroleMsgSchema = new Schema<AutoroleMsg>({
|
||||
guild: {type: Schema.Types.ObjectId, required: true},
|
||||
messageId: {type: String, required: true},
|
||||
emoji: {type: String, required: false},
|
||||
roleId: {type: String, required: true},
|
||||
});
|
||||
|
||||
export const autoroleMsgModel = model<AutoroleMsg>(
|
||||
'autoroleMsgModel', autoroleMsgSchema
|
||||
);
|
||||
@@ -1,22 +0,0 @@
|
||||
import {Schema, Types, model} from 'mongoose';
|
||||
|
||||
import {Guild} from './Guild';
|
||||
|
||||
export interface GiveawayMsg{
|
||||
_id: Types.ObjectId;
|
||||
guild: Guild;
|
||||
messageId: string;
|
||||
authorId: string;
|
||||
userIds: string[];
|
||||
}
|
||||
|
||||
const giveawayMsgSchema = new Schema<GiveawayMsg>({
|
||||
guild: {type: Schema.Types.ObjectId, required: true},
|
||||
messageId: {type: String, required: true},
|
||||
authorId: {type: String, required: true},
|
||||
userIds: {type: [{type: String}], default: []}
|
||||
});
|
||||
|
||||
export const giveawayMsgModel = model<GiveawayMsg>(
|
||||
'giveawayMsgModel', giveawayMsgSchema
|
||||
);
|
||||
@@ -1,23 +0,0 @@
|
||||
import {Schema, Types, model} from 'mongoose';
|
||||
|
||||
import {GiveawayMsg} from './GiveawayMsg';
|
||||
import {AutoroleMsg} from './AutoroleMsg';
|
||||
|
||||
export interface Guild{
|
||||
_id: Types.ObjectId;
|
||||
id: string;
|
||||
name: string;
|
||||
giveawayLogChannelId: string;
|
||||
autoroleLogChannelId: string;
|
||||
}
|
||||
|
||||
const guildSchema = new Schema<Guild>({
|
||||
id: {type: String, required: true},
|
||||
name: {type: String, required: true},
|
||||
giveawayLogChannelId: {type: String, required: false},
|
||||
autoroleLogChannelId: {type: String, required: false},
|
||||
});
|
||||
|
||||
export const guildModel = model<Guild>(
|
||||
'guildModel', guildSchema
|
||||
);
|
||||
@@ -1,14 +0,0 @@
|
||||
import {Schema, Types, model} from 'mongoose';
|
||||
|
||||
export interface Image{
|
||||
_id: Types.ObjectId; // act as random generated filename
|
||||
extension: string;
|
||||
}
|
||||
|
||||
const imageSchema = new Schema<Image>({
|
||||
extension: {type: String, required: true}
|
||||
});
|
||||
|
||||
export const imageModel = model<Image>(
|
||||
'imageModel', imageSchema
|
||||
);
|
||||
@@ -1,18 +0,0 @@
|
||||
import {Schema, Types, model} from 'mongoose';
|
||||
|
||||
export interface Token{
|
||||
_id: Types.ObjectId;
|
||||
token: string;
|
||||
guildId: string;
|
||||
exp: number;
|
||||
};
|
||||
|
||||
const tokenSchema = new Schema<Token>({
|
||||
token: {type: String, required: true},
|
||||
guildId: {type: String, required: true},
|
||||
exp: {type: Number, required: true}
|
||||
});
|
||||
|
||||
export const tokenModel = model<Token>(
|
||||
'tokenModel', tokenSchema
|
||||
);
|
||||
@@ -0,0 +1,23 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type Alias struct {
|
||||
bun.BaseModel `bun:"table:alias"`
|
||||
|
||||
Id int `bun:"id,pk,autoincrement"`
|
||||
GuildId int `bun:"guild_id,unique:text"`
|
||||
Alias string `bun:"alias,unique:text"`
|
||||
|
||||
Guild *Guild `bun:"belongs-to,join:guild_id=id"`
|
||||
Images []Image `bun:"m2m:alias_to_image,join:Alias=Image"`
|
||||
}
|
||||
|
||||
type AliasToImage struct {
|
||||
AliasId int `bun:"alias_id,pk"`
|
||||
Alias *Alias `bun:"rel:belongs-to,join:alias_id=id"`
|
||||
ImageId int `bun:"image_id,pk"`
|
||||
Image *Image `bun:"rel:belongs-to,join:image_id=id"`
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package models
|
||||
|
||||
import "github.com/uptrace/bun"
|
||||
|
||||
type AutoRoleMsg struct {
|
||||
bun.BaseModel `bun:"table:auto_role_msg"`
|
||||
|
||||
GuildId int `bun:"guild_id,pk"`
|
||||
MessageId string `bun:"message_id,pk"`
|
||||
RoleId string `bun:"role_id,notnull"`
|
||||
Emoji string `bun:"emoji"`
|
||||
|
||||
Guild *Guild `bun:"belongs-to:guild,join:guild_id=id"`
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package models
|
||||
|
||||
import "github.com/uptrace/bun"
|
||||
|
||||
type Guild struct {
|
||||
bun.BaseModel `bun:"table:guild"`
|
||||
|
||||
Id int64 `bun:"id,pk,autoincrement"`
|
||||
DcId string `bun:"dc_id,unique"`
|
||||
Name string `bun:"name,notnull"`
|
||||
|
||||
AutoRoleLogChanId string `bun:"auto_role_log_chan_id"`
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package models
|
||||
|
||||
import "github.com/uptrace/bun"
|
||||
|
||||
type Image struct {
|
||||
bun.BaseModel `bun:"table:image"`
|
||||
|
||||
Id int64 `bun:"id,pk,autoincrement"`
|
||||
Ext string `bun:"ext"`
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
import {config} from './config';
|
||||
import {guildModel} from './models/Guild';
|
||||
import {autoroleMsgModel} from './models/AutoroleMsg';
|
||||
import {giveawayMsgModel} from './models/GiveawayMsg';
|
||||
import {imageModel} from './models/Image';
|
||||
import {aliasModel} from './models/Alias';
|
||||
|
||||
async function resetMongo(): Promise<void> {
|
||||
try{
|
||||
await guildModel.deleteMany({});
|
||||
await autoroleMsgModel.deleteMany({});
|
||||
await giveawayMsgModel.deleteMany({});
|
||||
await imageModel.deleteMany({});
|
||||
await aliasModel.deleteMany({});
|
||||
}catch(err: unknown){
|
||||
throw new Error(`MongoDB reset failed. ${err}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function initializeMongo(): Promise<void> {
|
||||
try{
|
||||
if(config.mongodb.reset === 'true') await resetMongo();
|
||||
}catch(err: unknown){
|
||||
throw new Error(`MongoDB initialize failed. ${err}`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function runMongo(): Promise<void> {
|
||||
try {
|
||||
mongoose.set('strictQuery', false);
|
||||
const auth: string = `${config.mongodb.user}:${config.mongodb.pass}`;
|
||||
const server: string = `${config.mongodb.host}:${config.mongodb.port}`
|
||||
const uri: string = `mongodb://${auth}@${server}/${config.mongodb.db}`;
|
||||
await mongoose.connect(uri);
|
||||
} catch(err: unknown) {
|
||||
throw new Error(`MongoDB connection failed. ${err}`);
|
||||
}
|
||||
try {
|
||||
await initializeMongo();
|
||||
} catch(err: unknown) {
|
||||
throw new Error(`Initialize MongoDB data failed. ${err}`);
|
||||
}
|
||||
}
|
||||
Generated
-1312
File diff suppressed because it is too large.
Load diff
@@ -1,34 +0,0 @@
|
||||
{
|
||||
"name": "tanikaze-amane",
|
||||
"version": "1.0.1",
|
||||
"main": "index.ts",
|
||||
"scripts": {
|
||||
"test": "ts-node index.ts",
|
||||
"build": "npx tsc --build",
|
||||
"clean": "npx tsc --build --clean"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/konchinshih/Tanikaze-Amane.git"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"bugs": {
|
||||
"url": "https://github.com/konchinshih/Tanikaze-Amane/issues"
|
||||
},
|
||||
"homepage": "https://github.com/konchinshih/Tanikaze-Amane#readme",
|
||||
"dependencies": {
|
||||
"@types/node": "^20.3.2",
|
||||
"axios": "^1.6.2",
|
||||
"discord.js": "^14.11.0",
|
||||
"dotenv": "^16.3.1",
|
||||
"fs": "^0.0.1-security",
|
||||
"minio": "^8.0.1",
|
||||
"moment-timezone": "^0.5.43",
|
||||
"mongodb": "^5.6.0",
|
||||
"mongoose": "^8.0.1",
|
||||
"path": "^0.12.7",
|
||||
"typescript": "^5.1.3"
|
||||
},
|
||||
"description": ""
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package tracing
|
||||
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
"github.com/uptrace/opentelemetry-go-extra/otelzap"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
var (
|
||||
Tracer trace.Tracer
|
||||
Logger *otelzap.Logger
|
||||
|
||||
appname string = "amane"
|
||||
version string = "2.0.0-alpha1"
|
||||
)
|
||||
|
||||
func InitTracer() {
|
||||
Tracer = otel.Tracer(appname)
|
||||
|
||||
var l *zap.Logger
|
||||
var err error
|
||||
if viper.GetBool("zap-develop") {
|
||||
l, err = zap.NewDevelopment()
|
||||
} else {
|
||||
l, err = zap.NewProduction()
|
||||
}
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Logger = otelzap.New(l)
|
||||
}
|
||||
-109
@@ -1,109 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig to read more about this file */
|
||||
|
||||
/* Projects */
|
||||
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
||||
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
||||
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
||||
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
||||
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
||||
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
||||
|
||||
/* Language and Environment */
|
||||
"target": "es2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
||||
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
||||
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
||||
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
||||
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
||||
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
||||
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
||||
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
||||
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
||||
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
||||
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
||||
|
||||
/* Modules */
|
||||
"module": "commonJS", /* Specify what module code is generated. */
|
||||
// "rootDir": "./", /* Specify the root folder within your source files. */
|
||||
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
||||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
||||
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
||||
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
||||
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
||||
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
||||
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
||||
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
||||
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
||||
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
||||
// "resolveJsonModule": true, /* Enable importing .json files. */
|
||||
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
||||
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
||||
|
||||
/* JavaScript Support */
|
||||
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
||||
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
||||
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
||||
|
||||
/* Emit */
|
||||
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
||||
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
||||
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
||||
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
||||
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
||||
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
||||
// "outDir": "./", /* Specify an output folder for all emitted files. */
|
||||
// "removeComments": true, /* Disable emitting comments. */
|
||||
// "noEmit": true, /* Disable emitting files from a compilation. */
|
||||
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
||||
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
||||
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
||||
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
||||
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
||||
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
||||
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
||||
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
||||
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
||||
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
||||
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
||||
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
||||
|
||||
/* Interop Constraints */
|
||||
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
||||
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
||||
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
||||
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
||||
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
||||
|
||||
/* Type Checking */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
||||
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
||||
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
||||
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
||||
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
||||
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
||||
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
||||
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
||||
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
||||
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
||||
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
||||
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
||||
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
||||
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
||||
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
||||
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
||||
|
||||
/* Completeness */
|
||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"gitea.konchin.com/service/amane-tanikaze-dcbot/amane/models"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
func InitDB(db *bun.DB) {
|
||||
db.RegisterModel((*models.AliasToImage)(nil))
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Success(w http.ResponseWriter) error {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
_, err := io.WriteString(w,
|
||||
`{"code":200, "message": "success"}`+"\n")
|
||||
return err
|
||||
}
|
||||
Reference in new issue
Block a user