@minato-bot/plugin-gugu 2.0.4 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{and as e,between as t,defineRelations as n,desc as r,eq as i}from"drizzle-orm";import{bigint as a,bigserial as o,boolean as s,pgTable as c,text as l,timestamp as u}from"drizzle-orm/pg-core";import d from"node:path";import{useDb as f}from"@atri-bot/lib-db";import{randomInt as p}from"node:crypto";import{Plugin as m}from"@atri-bot/core";import h from"dayjs";import{Structs as g}from"node-napcat-ts";import _ from"yargs";const v={created_at:u().notNull().defaultNow(),updated_at:u().notNull().defaultNow().$onUpdate(()=>new Date)},y=c(`pigeons`,{user_id:o(`
|
|
1
|
+
import{and as e,between as t,defineRelations as n,desc as r,eq as i}from"drizzle-orm";import{bigint as a,bigserial as o,boolean as s,pgTable as c,text as l,timestamp as u}from"drizzle-orm/pg-core";import d from"node:path";import{useDb as f}from"@atri-bot/lib-db";import{randomInt as p}from"node:crypto";import{Plugin as m}from"@atri-bot/core";import h from"dayjs";import{Structs as g}from"node-napcat-ts";import _ from"yargs";const v={created_at:u().notNull().defaultNow(),updated_at:u().notNull().defaultNow().$onUpdate(()=>new Date)},y=c(`pigeons`,{user_id:o(`user_id`,{mode:`number`}).primaryKey(),pigeon_num:a(`pigeon_num`,{mode:`number`}).notNull(),gugued:s().notNull().default(!1),...v}),b=c(`pigeon_histories`,{id:o(`id`,{mode:`number`}).primaryKey(),user_id:o(`user_id`,{mode:`number`}).notNull(),operation:a(`operation`,{mode:`number`}).notNull(),prev_num:a(`prev_num`,{mode:`number`}).notNull(),current_num:a(`current_num`,{mode:`number`}).notNull(),reason:l(),...v}),x={Pigeons:y,PigeonHistories:b},S=n(x,e=>({PigeonHistories:{Pigeon:e.one.Pigeons({from:e.PigeonHistories.user_id,to:e.Pigeons.user_id})}}));var C=`@minato-bot/plugin-gugu`;let w=null;async function T(){return w||=await f({pluginName:C,config:{schema:x,relations:S},migration:{migrationsFolder:d.join(import.meta.dir,`../drizzle`)}}),w}async function E(e){let t=await T();return await t.query.Pigeons.findFirst({where:{user_id:e}})||(await t.insert(x.Pigeons).values({user_id:e,pigeon_num:0}),await E(e))}async function D(e,t,n){let r=await T(),a=await E(e);return t<0?!1:(await r.update(x.Pigeons).set({pigeon_num:a.pigeon_num+t,gugued:!0}).where(i(x.Pigeons.user_id,e)),await r.insert(x.PigeonHistories).values({user_id:e,operation:t,prev_num:a.pigeon_num,current_num:a.pigeon_num+t,reason:n}),!0)}async function O(e,t,n){let r=await T(),a=await E(e);return t<=0||a.pigeon_num-t<0?!1:(await r.update(x.Pigeons).set({pigeon_num:a.pigeon_num-t}).where(i(x.Pigeons.user_id,e)),await r.insert(x.PigeonHistories).values({user_id:e,operation:t,prev_num:a.pigeon_num+t,current_num:a.pigeon_num,reason:n}),!0)}const k=/咕咕/;async function A(n,r){let a=h();if(await(await T()).select().from(x.PigeonHistories).where(e(i(x.PigeonHistories.user_id,n),i(x.PigeonHistories.reason,`每日咕咕`),t(x.PigeonHistories.created_at,a.startOf(`day`).toDate(),a.endOf(`day`).toDate()))).then(e=>e.length>0))return[g.text(`今天已经咕咕过了! 明天再来吧!`)];let o=p(r[0],r[1]);return await D(n,o,`每日咕咕`)?[g.text(`咕咕成功! 获得 ${o} 只鸽子!`)]:[g.text(`修改鸽子数失败!`)]}const j=/我的鸽子|查鸽子/,M=_().option(`user_id`,{type:`number`,description:`要查询的用户ID,默认为自己`}),N=/鸽子排行/,P=_().option(`page`,{alias:`p`,type:`number`,description:`页码,默认为1`,default:1}).option(`size`,{alias:`s`,type:`number`,description:`每页数量,默认为10,最大20`,default:10}),F=new m(C).setDefaultConfig({addRange:[1,100],firstAdd:300}).onInstall(async({event:e,config:t,bot:n})=>{let i=await T();e.regCommandEvent({trigger:k,callback:async({context:e})=>{let r=e.user_id,a=await i.query.Pigeons.findFirst({where:{user_id:r}});(!a||!a.gugued)&&(await D(r,t.firstAdd,`初始赠送`),await n.sendMsg(e,[g.text(`欢迎第一次咕咕! 作为初始奖励, 你获得了 ${t.firstAdd} 只鸽子!`)]));let o=await A(r,t.addRange);await n.sendMsg(e,o)}}),e.regCommandEvent({trigger:j,commander:M,callback:async({context:e,options:t})=>{let r=await E(t.user_id??e.user_id),i=await n.getUsername({user_id:r.user_id});await n.sendMsg(e,[g.text(`用户 ${i} 共有 ${r.pigeon_num} 只鸽子!`)])}}),e.regCommandEvent({trigger:N,commander:P,callback:async({context:e,options:t})=>{let a=Math.max(1,t.page),o=Math.max(1,Math.min(20,t.size)),s=(a-1)*o,c=await i.select().from(x.Pigeons).orderBy(r(x.Pigeons.pigeon_num)).limit(o).offset(s);if(c.length===0){await n.sendMsg(e,[g.text(`暂无鸽子数据!`)]);return}let l=await i.select().from(x.Pigeons),u=Math.ceil(l.length/o),d=await Promise.all(c.map(async(e,t)=>{let r=await n.getUsername({user_id:e.user_id});return`${s+t+1}. 用户: ${r} 共有 ${e.pigeon_num} 只鸽子`}));await n.sendMsg(e,[g.text(`鸽子排行 (第 ${a} 页 / 共 ${u} 页):\n${d.join(`
|
|
2
2
|
`)}`)])}})});export{b as PigeonHistories,y as Pigeons,S as Relations,x as Schema,D as addUserPigeonNum,T as getDrizzle,E as getUserPigeonInfo,k as guguPluginGuguRegexp,A as handleGuguCommand,P as pigeonRankCommander,N as pigeonRankRegexp,F as plugin,M as queryPigeonCommander,j as queryPigeonRegexp,O as reduceUserPigeonNum,v as timestamps};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ALTER TABLE "pigeons" RENAME COLUMN "id" TO "user_id";
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "8",
|
|
3
|
+
"dialect": "postgres",
|
|
4
|
+
"id": "773a9e06-4af7-484b-8f59-ee68daa7b6e6",
|
|
5
|
+
"prevIds": [
|
|
6
|
+
"27cf092f-66d5-4bc1-a950-1f7f8e1ea81f"
|
|
7
|
+
],
|
|
8
|
+
"ddl": [
|
|
9
|
+
{
|
|
10
|
+
"isRlsEnabled": false,
|
|
11
|
+
"name": "pigeon_histories",
|
|
12
|
+
"entityType": "tables",
|
|
13
|
+
"schema": "public"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"isRlsEnabled": false,
|
|
17
|
+
"name": "pigeons",
|
|
18
|
+
"entityType": "tables",
|
|
19
|
+
"schema": "public"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"type": "bigserial",
|
|
23
|
+
"typeSchema": null,
|
|
24
|
+
"notNull": true,
|
|
25
|
+
"dimensions": 0,
|
|
26
|
+
"default": null,
|
|
27
|
+
"generated": null,
|
|
28
|
+
"identity": null,
|
|
29
|
+
"name": "id",
|
|
30
|
+
"entityType": "columns",
|
|
31
|
+
"schema": "public",
|
|
32
|
+
"table": "pigeon_histories"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"type": "bigserial",
|
|
36
|
+
"typeSchema": null,
|
|
37
|
+
"notNull": true,
|
|
38
|
+
"dimensions": 0,
|
|
39
|
+
"default": null,
|
|
40
|
+
"generated": null,
|
|
41
|
+
"identity": null,
|
|
42
|
+
"name": "user_id",
|
|
43
|
+
"entityType": "columns",
|
|
44
|
+
"schema": "public",
|
|
45
|
+
"table": "pigeon_histories"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"type": "bigint",
|
|
49
|
+
"typeSchema": null,
|
|
50
|
+
"notNull": true,
|
|
51
|
+
"dimensions": 0,
|
|
52
|
+
"default": null,
|
|
53
|
+
"generated": null,
|
|
54
|
+
"identity": null,
|
|
55
|
+
"name": "operation",
|
|
56
|
+
"entityType": "columns",
|
|
57
|
+
"schema": "public",
|
|
58
|
+
"table": "pigeon_histories"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"type": "bigint",
|
|
62
|
+
"typeSchema": null,
|
|
63
|
+
"notNull": true,
|
|
64
|
+
"dimensions": 0,
|
|
65
|
+
"default": null,
|
|
66
|
+
"generated": null,
|
|
67
|
+
"identity": null,
|
|
68
|
+
"name": "prev_num",
|
|
69
|
+
"entityType": "columns",
|
|
70
|
+
"schema": "public",
|
|
71
|
+
"table": "pigeon_histories"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"type": "bigint",
|
|
75
|
+
"typeSchema": null,
|
|
76
|
+
"notNull": true,
|
|
77
|
+
"dimensions": 0,
|
|
78
|
+
"default": null,
|
|
79
|
+
"generated": null,
|
|
80
|
+
"identity": null,
|
|
81
|
+
"name": "current_num",
|
|
82
|
+
"entityType": "columns",
|
|
83
|
+
"schema": "public",
|
|
84
|
+
"table": "pigeon_histories"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"type": "text",
|
|
88
|
+
"typeSchema": null,
|
|
89
|
+
"notNull": false,
|
|
90
|
+
"dimensions": 0,
|
|
91
|
+
"default": null,
|
|
92
|
+
"generated": null,
|
|
93
|
+
"identity": null,
|
|
94
|
+
"name": "reason",
|
|
95
|
+
"entityType": "columns",
|
|
96
|
+
"schema": "public",
|
|
97
|
+
"table": "pigeon_histories"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"type": "timestamp",
|
|
101
|
+
"typeSchema": null,
|
|
102
|
+
"notNull": true,
|
|
103
|
+
"dimensions": 0,
|
|
104
|
+
"default": "now()",
|
|
105
|
+
"generated": null,
|
|
106
|
+
"identity": null,
|
|
107
|
+
"name": "created_at",
|
|
108
|
+
"entityType": "columns",
|
|
109
|
+
"schema": "public",
|
|
110
|
+
"table": "pigeon_histories"
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"type": "timestamp",
|
|
114
|
+
"typeSchema": null,
|
|
115
|
+
"notNull": true,
|
|
116
|
+
"dimensions": 0,
|
|
117
|
+
"default": "now()",
|
|
118
|
+
"generated": null,
|
|
119
|
+
"identity": null,
|
|
120
|
+
"name": "updated_at",
|
|
121
|
+
"entityType": "columns",
|
|
122
|
+
"schema": "public",
|
|
123
|
+
"table": "pigeon_histories"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"type": "bigserial",
|
|
127
|
+
"typeSchema": null,
|
|
128
|
+
"notNull": true,
|
|
129
|
+
"dimensions": 0,
|
|
130
|
+
"default": null,
|
|
131
|
+
"generated": null,
|
|
132
|
+
"identity": null,
|
|
133
|
+
"name": "user_id",
|
|
134
|
+
"entityType": "columns",
|
|
135
|
+
"schema": "public",
|
|
136
|
+
"table": "pigeons"
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"type": "bigint",
|
|
140
|
+
"typeSchema": null,
|
|
141
|
+
"notNull": true,
|
|
142
|
+
"dimensions": 0,
|
|
143
|
+
"default": null,
|
|
144
|
+
"generated": null,
|
|
145
|
+
"identity": null,
|
|
146
|
+
"name": "pigeon_num",
|
|
147
|
+
"entityType": "columns",
|
|
148
|
+
"schema": "public",
|
|
149
|
+
"table": "pigeons"
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
"type": "boolean",
|
|
153
|
+
"typeSchema": null,
|
|
154
|
+
"notNull": true,
|
|
155
|
+
"dimensions": 0,
|
|
156
|
+
"default": "false",
|
|
157
|
+
"generated": null,
|
|
158
|
+
"identity": null,
|
|
159
|
+
"name": "gugued",
|
|
160
|
+
"entityType": "columns",
|
|
161
|
+
"schema": "public",
|
|
162
|
+
"table": "pigeons"
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
"type": "timestamp",
|
|
166
|
+
"typeSchema": null,
|
|
167
|
+
"notNull": true,
|
|
168
|
+
"dimensions": 0,
|
|
169
|
+
"default": "now()",
|
|
170
|
+
"generated": null,
|
|
171
|
+
"identity": null,
|
|
172
|
+
"name": "created_at",
|
|
173
|
+
"entityType": "columns",
|
|
174
|
+
"schema": "public",
|
|
175
|
+
"table": "pigeons"
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
"type": "timestamp",
|
|
179
|
+
"typeSchema": null,
|
|
180
|
+
"notNull": true,
|
|
181
|
+
"dimensions": 0,
|
|
182
|
+
"default": "now()",
|
|
183
|
+
"generated": null,
|
|
184
|
+
"identity": null,
|
|
185
|
+
"name": "updated_at",
|
|
186
|
+
"entityType": "columns",
|
|
187
|
+
"schema": "public",
|
|
188
|
+
"table": "pigeons"
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
"columns": [
|
|
192
|
+
"id"
|
|
193
|
+
],
|
|
194
|
+
"nameExplicit": false,
|
|
195
|
+
"name": "pigeon_histories_pkey",
|
|
196
|
+
"schema": "public",
|
|
197
|
+
"table": "pigeon_histories",
|
|
198
|
+
"entityType": "pks"
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
"columns": [
|
|
202
|
+
"user_id"
|
|
203
|
+
],
|
|
204
|
+
"nameExplicit": false,
|
|
205
|
+
"name": "pigeons_pkey",
|
|
206
|
+
"schema": "public",
|
|
207
|
+
"table": "pigeons",
|
|
208
|
+
"entityType": "pks"
|
|
209
|
+
}
|
|
210
|
+
],
|
|
211
|
+
"renames": [
|
|
212
|
+
"public.pigeons.id->public.pigeons.user_id"
|
|
213
|
+
]
|
|
214
|
+
}
|