This repository has been archived by the owner on Apr 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
upload.go
212 lines (138 loc) · 4.81 KB
/
upload.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/***********************************************************************************************************************
*** P R O J E C T -- S H I Z U K U Q I A N J U N A K A S U M I ***
************************************************************************************************************************
* Basic:
*
* Package Name : meme
* File Name : upload.go
* File Path : internal/app/meme/
* Author : Qianjunakasumi
* Description : 上传表情
*
*----------------------------------------------------------------------------------------------------------------------*
* Copyright:
*
* Copyright (C) 2020-present QianjuNakasumi
*
* E-mail qianjunakasumi@gmail.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://github.com/qianjunakasumi/project-shizuku/blob/master/LICENSE.
*----------------------------------------------------------------------------------------------------------------------*/
package meme
import (
"github.com/qianjunakasumi/project-shizuku/internal/shizuku"
)
type uploadMeme struct {
//root string
}
func (r uploadMeme) OnCall(qm *shizuku.QQMsg, sz *shizuku.SHIZUKU) (rm *shizuku.Message, err error) {
// 字段是必须的
if c := qm.Call["idol"]; c != "_SHIZUKU默认检查专用" {
qm.Type = sz.FuzzyGetIdol(c)
}
rm = shizuku.NewText("欢迎使用表情上传,请发送您将上传的图片\n\n您上传的图片由 Project-SHIZUKU 服务器保存在中国香港。上传表情的同时会收集您的帐号信息:您的QQ号和当前群号。如您不同意上述方法,请勿使用本功能,使用“取消”退出")
return
}
func (r uploadMeme) OnJobCall(_ *shizuku.QQMsg, _ *shizuku.SHIZUKU) (rm *shizuku.Message, err error) {
return
}
/*
var (
UploadMeme = uploadMeme
Uploading = uploading
Agree = agree
)
func checkAgreeStatus(id uint64) (bool, error) {
rows, err := database.DB.Query(`SELECT * FROM meme_upload_agreeer WHERE meme_upload_agreeer.qqID = ?`, id)
if err != nil {
return false, err
}
defer rows.Close()
if !rows.Next() {
return false, nil
}
return true, nil
}
func agreeTerm(id uint64, name string, id2 uint64) error {
insert, err := database.DB.Prepare(`INSERT INTO meme_upload_agreeer ( qqID, agreeInfo ) VALUES ( ?, ? )`)
if err != nil {
return err
}
defer insert.Close()
_, err = insert.Exec(
id,
`{"groupName": "`+
name+`", "groupID": `+
strconv.FormatUint(id2, 10)+`, "time": "`+
time.Now().Format(time.RFC3339)+`"}`,
)
if err != nil {
return err
}
return nil
}
func agree(call string, info *message.Info) (*message.Chain, error) {
call = strings.ReplaceAll(call, " ", "")
m := new(message.Chain)
if call != "我同意" {
m.Cancel()
return m, nil
}
err := agreeTerm(info.UserId, info.GroupName, info.GroupId)
if err != nil {
return m, nil
}
configs.QuoteJob[info.UserId] = nil
configs.ImageJob[info.UserId] = &Uploading
m.AddText("您已同意协议。请您发送欲上传的图片")
return m, nil
}
func uploading(call string, info *message.Info) (*message.Chain, error) {
m := new(message.Chain)
m.AddText("您的图片已经上传。")
m.AddText("\n图片的地址为:" + call)
configs.ImageJob[info.UserId] = nil
// 下载图片到内存中
// 计算图片的SHA1值
// 读取数据库检测是否有匹配的sha1
// 若有则返回,图片已存在
// 若无则将图片保存至目录下,以sha1值命名
// 向数据库写入事件
return m, nil
}
func uploadMeme(calls map[string]string, info *message.Info) (*message.Chain, error) {
var (
m = new(message.Chain)
isAgree, err = checkAgreeStatus(info.UserId)
)
if info.UserId > 2200000000 {
m.AddText("您未在灰度测试范围中,请您耐心等待下一版本更新,谢谢。")
return m, nil
}
if err != nil {
return m, err
}
if isAgree {
configs.ImageJob[info.UserId] = &Uploading
m.AddText("请您发送欲上传的图片")
return m, nil
}
m.AddAt(info.UserId)
m.AddText("请您阅读以下协议,同意后方可开始上传\n")
m.AddImage("assets/terms/uploadMeme.jpg")
m.AddText("\n\n同意协议请回复本条消息:“我同意”")
configs.QuoteJob[info.UserId] = &Agree
return m, nil
}
*/