1
+ import plugin from '../../../lib/plugins/plugin.js'
2
+ import MysApi from '../model/mys/mysApi.js'
3
+ import Cfg from '../model/Cfg.js'
4
+ import fs from 'node:fs'
5
+ import _ from 'lodash'
6
+
7
+ export class ji_config extends plugin {
8
+ constructor ( ) {
9
+ super ( {
10
+ name : '寄·配置' ,
11
+ dsc : '' ,
12
+ event : 'message' ,
13
+ priority : Cfg . getConfig ( 'config' ) . priority ?? - 114514 ,
14
+ rule : [
15
+ {
16
+ reg : / ^ # ( 社 区 ) ? 签 到 ( 添 加 | 删 除 ) ? ( 白 名 单 | 推 送 ) ( 群 ) ? .* $ / i,
17
+ permission : 'master' ,
18
+ fnc : 'setwhite'
19
+ } ,
20
+ {
21
+ reg : '^#?(开启|关闭)崩三签到$' ,
22
+ fnc : 'setbh3'
23
+ } ,
24
+ {
25
+ reg : '^#?设置社区签到(经验|米币)$' ,
26
+ fnc : 'setbbs'
27
+ } ,
28
+ {
29
+ reg : '^#?(原神|星铁|崩三)?(禁用|解禁)(uid)?\\s*[1-9][0-9]{8}$' ,
30
+ fnc : 'banUid'
31
+ } ,
32
+ {
33
+ reg : '^#?寄(替换|还原)$' ,
34
+ permission : 'master' ,
35
+ fnc : 'jicopy'
36
+ }
37
+ ]
38
+ } )
39
+ }
40
+
41
+ async setwhite ( e ) {
42
+ let white = Cfg . getConfig ( 'white' )
43
+ let id = e . msg . replace ( / # ( 社 区 ) ? 签 到 ( 添 加 | 删 除 ) ? ( 白 名 单 | 推 送 ) ( 群 ) ? \s * / i, '' ) . trim ( )
44
+ if ( e . msg . includes ( '群' ) || e . msg . includes ( '推送' ) ) return e . reply ( '建议使用锅巴配置' )
45
+
46
+ let action = e . msg . includes ( '添加' ) ? '添加' : '删除'
47
+ let set = white [ e . msg . includes ( '群' ) ? 'Group' : e . msg . includes ( '社区' ) ? 'bbsQQ' : 'QQ' ]
48
+ let name = e . msg . includes ( '群' ) ? '群' : 'QQ'
49
+ let push = e . msg . includes ( '推送' ) ? '推送' : '白'
50
+
51
+ if ( ! id ) id = e . user_id
52
+
53
+ id = Number ( id ) || String ( id )
54
+
55
+ if ( action === '添加' ) {
56
+ if ( set && set . includes ( id ) )
57
+ return e . reply ( `${ name } :${ id } 已在${ push } 名单中` )
58
+ set . push ( id )
59
+ Cfg . setConfig ( 'white' , white )
60
+ return e . reply ( `已${ action } ${ push } 名单${ name } :${ id } ` )
61
+ } else if ( action === '删除' ) {
62
+ if ( set . length === 0 )
63
+ return e . reply ( `未添加${ push } 名单${ name } ` )
64
+
65
+ let index = set . findIndex ( q => q == id )
66
+ if ( index !== - 1 ) {
67
+ set . splice ( index , 1 )
68
+ Cfg . setConfig ( 'white' , white )
69
+ e . reply ( `已${ action } ${ push } 名单${ name } :${ id } ` )
70
+ } else {
71
+ e . reply ( `${ name } :${ id } 未在${ push } 名单中` )
72
+ }
73
+ return
74
+ } else {
75
+ let msg = set . slice ( )
76
+ msg = msg . map ( ( e , i ) => `${ i + 1 } . ${ e } ` ) . join ( ', ' )
77
+ return e . reply ( msg , false )
78
+ }
79
+ }
80
+
81
+ async setbh3 ( e ) {
82
+ let id = Number ( e . user_id ) || String ( e . user_id )
83
+ let config = Cfg . getConfig ( 'config' )
84
+ let white = Cfg . getConfig ( 'white' )
85
+ if ( ! config . game ?. includes ( 'bh3' ) )
86
+ return e . reply ( '主人未启用崩坏三签到' )
87
+
88
+ let { cks, uids } = await Cfg . getcks ( false , e . user_id )
89
+
90
+ if ( _ . every ( cks , _ . isEmpty ) )
91
+ return e . reply ( '\n请【#扫码登录】或【#刷新ck】后再开启' , false , { at : true } )
92
+
93
+ let msgs = [ ] ; let cknum = 0
94
+
95
+ for ( let i = 0 ; i < uids . bh3 . length ; i ++ ) {
96
+ let uid = uids . bh3 [ i ] ; let ck = cks . bh3 [ uid ]
97
+ let mysApi = new MysApi ( ck . uid , ck . ck , { log : false } , 'bh3' , ck . region )
98
+ let signInfo = await mysApi . getData ( 'sign_info' )
99
+ if ( ( signInfo ?. retcode == - 100 && signInfo ?. message == '尚未登录' ) || signInfo ?. message . includes ( '请登录后重试' ) ) {
100
+ msgs . push ( `\n崩三uid:${ ck . uid } ,ck失效` )
101
+ cknum ++
102
+ }
103
+ await common . sleep ( 500 )
104
+ }
105
+ msgs . push ( '\n请【#扫码登录】或【#刷新ck】' )
106
+ if ( cknum > 0 ) return e . reply ( msgs , false , { at : true } )
107
+
108
+ let action = e . msg . includes ( '开启' ) ? '开启' : '关闭'
109
+ let set = white . bh3QQ
110
+
111
+ if ( action === '开启' ) {
112
+ if ( set ?. includes ( id ) )
113
+ return e . reply ( `\n你已开启过崩坏三签到${ white [ 'QQ' ] ?. includes ( id ) ? '' : '\n如需自动签到请【#开启自动签到】' } ` , false , { at : true } )
114
+
115
+ set . push ( id )
116
+ Cfg . setConfig ( 'white' , white )
117
+ return e . reply ( `\n已开启崩坏三签到${ white [ 'QQ' ] ?. includes ( id ) ? '' : '\n如需自动签到请【#开启自动签到】' } ` , false , { at : true } )
118
+ } else if ( action === '关闭' ) {
119
+ if ( set . length === 0 )
120
+ return e . reply ( `还没有人开启崩坏三签到哦...` )
121
+
122
+ let index = set . findIndex ( q => q == id )
123
+ if ( index !== - 1 ) {
124
+ set . splice ( index , 1 )
125
+ Cfg . setConfig ( 'white' , white )
126
+ e . reply ( `已关闭崩坏三签到...` , false , { at : true } )
127
+ } else {
128
+ e . reply ( `你还没有开启崩坏三签到哦...` , false , { at : true } )
129
+ }
130
+ return
131
+ }
132
+ }
133
+
134
+ async setbbs ( e ) {
135
+ let white = Cfg . getConfig ( 'white' )
136
+ let id = Number ( e . user_id ) || String ( e . user_id )
137
+
138
+ if ( e . msg . includes ( '经验' ) ) {
139
+ if ( white . exQQ ?. includes ( id ) )
140
+ return e . reply ( `\n当前社区签到模式:【米币+经验】` , false , { at : true } )
141
+
142
+ white . exQQ . push ( id )
143
+ Cfg . setConfig ( 'white' , white )
144
+ return e . reply ( `\n社区签到模式已设置:【米币+经验】` , false , { at : true } )
145
+ } else if ( e . msg . includes ( '米币' ) ) {
146
+ if ( white . exQQ . length === 0 )
147
+ return e . reply ( `\n当前社区签到模式:【米币】` , false , { at : true } )
148
+
149
+ let index = white . exQQ . findIndex ( q => q == id )
150
+ if ( index !== - 1 ) {
151
+ white . exQQ . splice ( index , 1 )
152
+ Cfg . setConfig ( 'white' , white )
153
+ e . reply ( `\n社区签到模式已设置:【米币】` , false , { at : true } )
154
+ } else {
155
+ e . reply ( `\n当前社区签到模式:【米币】` , false , { at : true } )
156
+ }
157
+ return
158
+ }
159
+ }
160
+
161
+ async banUid ( e ) {
162
+ let uid = Number ( e . msg . replace ( / # ? ( 原 神 | 星 铁 | 崩 三 ) ? ( 禁 用 | 解 禁 ) ( u i d ) ? \s * / i, '' ) . trim ( ) )
163
+
164
+ if ( ! uid ) return e . reply ( '未输入UID' )
165
+
166
+ let Uid = Cfg . getConfig ( 'banuid' )
167
+
168
+ let name = e . msg . includes ( '星铁' ) ? '星铁' : e . msg . includes ( '崩三' ) ? '崩三' : '原神'
169
+ let set = Uid [ e . msg . includes ( '星铁' ) ? 'sr' : e . msg . includes ( '崩三' ) ? 'bh3' : 'gs' ]
170
+ let action = e . msg . includes ( '禁用' ) ? '禁用' : '解禁'
171
+ let g = e . msg . includes ( '星铁' ) ? 'sr' : e . msg . includes ( '崩三' ) ? 'bh3' : 'gs'
172
+
173
+ if ( ! e . isMaster ) {
174
+ let { cks } = await Cfg . getcks ( false , e . user_id )
175
+ if ( _ . isEmpty ( cks [ g ] ) )
176
+ return e . reply ( '未绑定ck,或此UID已禁用' , false , { at : true } )
177
+ if ( ! cks [ g ] [ uid ] )
178
+ return e . reply ( `只能${ action } 自己已绑ck的uid\n或此UID已禁用` )
179
+ }
180
+
181
+ if ( action === '禁用' ) {
182
+ if ( set && set . includes ( uid ) )
183
+ return e . reply ( `${ name } UID:${ uid } 已禁用` )
184
+
185
+ set . push ( uid )
186
+ Cfg . setConfig ( 'banuid' , Uid )
187
+ return e . reply ( `已${ action } ${ name } UID:${ uid } ` )
188
+ } else {
189
+ if ( set . length === 0 )
190
+ return e . reply ( `未添加禁用UID` )
191
+
192
+ let index = set . findIndex ( q => q == uid )
193
+ if ( index !== - 1 ) {
194
+ set . splice ( index , 1 )
195
+ Cfg . setConfig ( 'banuid' , Uid )
196
+ e . reply ( `已${ action } ${ name } UID:${ uid } ` )
197
+ } else {
198
+ e . reply ( `${ name } UID:${ uid } 未禁用` )
199
+ }
200
+ return
201
+ }
202
+ }
203
+
204
+ async jicopy ( e ) {
205
+ let info = './plugins/genshin/model/mys/mysInfo.js'
206
+ if ( ! fs . existsSync ( `${ Cfg . resfile } temp` ) )
207
+ fs . mkdirSync ( `${ Cfg . resfile } temp` )
208
+
209
+ if ( e . msg . includes ( '替换' ) ) {
210
+ if ( fs . existsSync ( `${ Cfg . resfile } temp/mysInfo.js` ) )
211
+ return e . reply ( '已有未还原备份,若无更新冲突无需替换\n否则请【#寄还原】后更新本体再替换' )
212
+ fs . copyFileSync ( info , `${ Cfg . resfile } temp/mysInfo.js` )
213
+ fs . copyFileSync ( `${ Cfg . defile } /mysInfo.js` , info )
214
+ return e . reply ( '替换成功,重启后生效' )
215
+ } else {
216
+ if ( ! fs . existsSync ( `${ Cfg . resfile } temp/mysInfo.js` ) )
217
+ return e . reply ( '你还没有替换过,无法还原哦' )
218
+ fs . copyFileSync ( `${ Cfg . resfile } temp/mysInfo.js` , info )
219
+ fs . unlinkSync ( `${ Cfg . resfile } temp/mysInfo.js` )
220
+ return e . reply ( '还原成功' )
221
+ }
222
+ }
223
+ }
0 commit comments