message
This commit is contained in:
parent
10aebe67e7
commit
9bfa5a9b9c
11
.vscode/launch.json
vendored
11
.vscode/launch.json
vendored
@ -1,15 +1,12 @@
|
||||
{
|
||||
// 使用 IntelliSense 了解相关属性。
|
||||
// 悬停以查看现有属性的描述。
|
||||
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "pwa-chrome",
|
||||
"type": "node-terminal",
|
||||
"name": "Run Script: start",
|
||||
"request": "launch",
|
||||
"name": "Launch Chrome against localhost",
|
||||
"url": "http://localhost:8080",
|
||||
"webRoot": "${workspaceFolder}"
|
||||
"command": "yarn run start",
|
||||
"cwd": "${workspaceFolder}"
|
||||
}
|
||||
]
|
||||
}
|
@ -14,11 +14,11 @@ ws.on('GUILD_MEMBERS', (data) => {
|
||||
console.log('[GUILD_MEMBERS] 事件接收 :', data);
|
||||
});
|
||||
ws.on('GUILD_MESSAGES', (data) => {
|
||||
// console.log('[GUILD_MESSAGES] 事件接收 :', JSON.stringify(data));
|
||||
console.log('[GUILD_MESSAGES] 事件接收 :', JSON.stringify(data));
|
||||
if(data.eventType == "MESSAGE_CREATE"){
|
||||
messageCreate(data.msg)
|
||||
messageCreate(data)
|
||||
}else if(data.eventType == "MESSAGE_DELETE"){
|
||||
messageDelete(data.msg)
|
||||
messageDelete(data)
|
||||
}
|
||||
});
|
||||
ws.on('GUILD_MESSAGE_REACTIONS', (data) => {
|
||||
|
6
bin/channel-core/tools.js
Normal file
6
bin/channel-core/tools.js
Normal file
@ -0,0 +1,6 @@
|
||||
import { client } from "./base.js";
|
||||
|
||||
export async function getRole(guildId){
|
||||
let { data } = await client.roleApi.roles(guildId);
|
||||
return data
|
||||
}
|
31
bin/mysql/base.js
Normal file
31
bin/mysql/base.js
Normal file
@ -0,0 +1,31 @@
|
||||
import mysql from "mysql"
|
||||
import { mysqlConfig } from "../../config/index.js";
|
||||
|
||||
|
||||
function connection(){
|
||||
return new Promise((res,rej)=>{
|
||||
const c = mysql.createConnection(mysqlConfig);
|
||||
c.connect(function (err) {
|
||||
if (err) {
|
||||
throw new Error("connect mysql error",err)
|
||||
}
|
||||
|
||||
res(c)
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
export function query(sql){
|
||||
return new Promise(async (res)=>{
|
||||
const c = await connection()
|
||||
c.query(sql,(err,data)=>{
|
||||
if(err){
|
||||
throw new Error("select error")
|
||||
}else {
|
||||
c.destroy()
|
||||
res(data)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
}
|
24
bin/mysql/index.js
Normal file
24
bin/mysql/index.js
Normal file
@ -0,0 +1,24 @@
|
||||
import { mysqlConfig } from "../../config/index.js"
|
||||
import { query } from "./base.js"
|
||||
|
||||
const dataname = mysqlConfig.database
|
||||
/**
|
||||
* 判断数据表是否存在
|
||||
* @param {String} name 数据表名
|
||||
* @return {Boolend} true 存在 false 不存在
|
||||
*/
|
||||
|
||||
|
||||
export async function isTable(name){
|
||||
const list = await query("show tables")
|
||||
for(const i in list){
|
||||
console.log(list[i]["Tables_in_" + dataname])
|
||||
if(name == list[i]["Tables_in_" + dataname]){
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
console.log(await isTable("aaa"))
|
7
config/index.js
Normal file
7
config/index.js
Normal file
@ -0,0 +1,7 @@
|
||||
export const mysqlConfig = {
|
||||
host: "localhost",
|
||||
port: 3306,
|
||||
database: "qqbot",
|
||||
user: "root",
|
||||
password: "root"
|
||||
}
|
@ -4,7 +4,10 @@
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"dayjs": "^1.11.2",
|
||||
"memory-cache": "^0.2.0",
|
||||
"mitt": "^3.0.0",
|
||||
"mysql": "^2.18.1",
|
||||
"qq-guild-bot": "^2.9.4"
|
||||
},
|
||||
"scripts": {
|
||||
|
@ -1,10 +1,33 @@
|
||||
import dayjs from "dayjs"
|
||||
import { getRole } from "../../bin/channel-core/tools.js"
|
||||
import { onMessageCreate } from "../../bin/message/index.js"
|
||||
|
||||
|
||||
function init(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
async function updateActive(member,author,guildId){
|
||||
const jointime = dayjs(member.joined_at)
|
||||
// console.log(time.format('YYYY-MM-DD HH:mm:ss'))
|
||||
const nickname = member.nick
|
||||
const roles = []
|
||||
const avatar = author.avatar
|
||||
const id = author.id
|
||||
const bot = author.bot
|
||||
const username = author.username
|
||||
const roleList = await getRole(guildId)
|
||||
console.log(roleList)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 收到消息处理函数
|
||||
* @param {Object} msg 消息对象
|
||||
*/
|
||||
function createMessage(msg){
|
||||
function createMessage({msg}){
|
||||
console.log("收到消息",msg)
|
||||
updateActive(msg.member,msg.author,msg.guild_id)
|
||||
}
|
||||
onMessageCreate(createMessage)
|
80
yarn.lock
80
yarn.lock
@ -15,6 +15,11 @@ axios@>=0.21.1:
|
||||
follow-redirects "^1.14.9"
|
||||
form-data "^4.0.0"
|
||||
|
||||
bignumber.js@9.0.0:
|
||||
version "9.0.0"
|
||||
resolved "https://registry.npmmirror.com/bignumber.js/-/bignumber.js-9.0.0.tgz#805880f84a329b5eac6e7cb6f8274b6d82bdf075"
|
||||
integrity sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A==
|
||||
|
||||
combined-stream@^1.0.8:
|
||||
version "1.0.8"
|
||||
resolved "https://registry.npmmirror.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
|
||||
@ -22,6 +27,16 @@ combined-stream@^1.0.8:
|
||||
dependencies:
|
||||
delayed-stream "~1.0.0"
|
||||
|
||||
core-util-is@~1.0.0:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.npmmirror.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85"
|
||||
integrity sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==
|
||||
|
||||
dayjs@^1.11.2:
|
||||
version "1.11.2"
|
||||
resolved "https://registry.npmmirror.com/dayjs/-/dayjs-1.11.2.tgz#fa0f5223ef0d6724b3d8327134890cfe3d72fbe5"
|
||||
integrity sha512-F4LXf1OeU9hrSYRPTTj/6FbO4HTjPKXvEIC1P2kcnFurViINCVk3ZV0xAS3XVx9MkMsXbbqlK6hjseaYbgKEHw==
|
||||
|
||||
delayed-stream@~1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.npmmirror.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
|
||||
@ -41,11 +56,26 @@ form-data@^4.0.0:
|
||||
combined-stream "^1.0.8"
|
||||
mime-types "^2.1.12"
|
||||
|
||||
inherits@~2.0.3:
|
||||
version "2.0.4"
|
||||
resolved "https://registry.npmmirror.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
|
||||
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
|
||||
|
||||
isarray@~1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.npmmirror.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
|
||||
integrity sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==
|
||||
|
||||
loglevel@^1.8.0:
|
||||
version "1.8.0"
|
||||
resolved "https://registry.npmmirror.com/loglevel/-/loglevel-1.8.0.tgz#e7ec73a57e1e7b419cb6c6ac06bf050b67356114"
|
||||
integrity sha512-G6A/nJLRgWOuuwdNuA6koovfEV1YpqqAG4pRUlFaz3jj2QNZ8M4vBqnVA+HBTmU/AMNUtlOsMmSpF6NyOjztbA==
|
||||
|
||||
memory-cache@^0.2.0:
|
||||
version "0.2.0"
|
||||
resolved "https://registry.npmmirror.com/memory-cache/-/memory-cache-0.2.0.tgz#7890b01d52c00c8ebc9d533e1f8eb17e3034871a"
|
||||
integrity sha512-OcjA+jzjOYzKmKS6IQVALHLVz+rNTMPoJvCztFaZxwG14wtAW7VRZjwTQu06vKCYOxh4jVnik7ya0SXTB0W+xA==
|
||||
|
||||
mime-db@1.52.0:
|
||||
version "1.52.0"
|
||||
resolved "https://registry.npmmirror.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
|
||||
@ -63,6 +93,21 @@ mitt@^3.0.0:
|
||||
resolved "https://registry.npmmirror.com/mitt/-/mitt-3.0.0.tgz#69ef9bd5c80ff6f57473e8d89326d01c414be0bd"
|
||||
integrity sha512-7dX2/10ITVyqh4aOSVI9gdape+t9l2/8QxHrFmUXu4EEUpdlxl6RudZUPZoc+zuY2hk1j7XxVroIVIan/pD/SQ==
|
||||
|
||||
mysql@^2.18.1:
|
||||
version "2.18.1"
|
||||
resolved "https://registry.npmmirror.com/mysql/-/mysql-2.18.1.tgz#2254143855c5a8c73825e4522baf2ea021766717"
|
||||
integrity sha512-Bca+gk2YWmqp2Uf6k5NFEurwY/0td0cpebAucFpY/3jhrwrVGuxU2uQFCHjU19SJfje0yQvi+rVWdq78hR5lig==
|
||||
dependencies:
|
||||
bignumber.js "9.0.0"
|
||||
readable-stream "2.3.7"
|
||||
safe-buffer "5.1.2"
|
||||
sqlstring "2.3.1"
|
||||
|
||||
process-nextick-args@~2.0.0:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.npmmirror.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
|
||||
integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==
|
||||
|
||||
qq-guild-bot@^2.9.4:
|
||||
version "2.9.4"
|
||||
resolved "https://registry.npmmirror.com/qq-guild-bot/-/qq-guild-bot-2.9.4.tgz#5c697746fa9402a3c4537dd983571444ba497b1d"
|
||||
@ -72,6 +117,19 @@ qq-guild-bot@^2.9.4:
|
||||
resty-client "0.0.5"
|
||||
ws "^7.4.4"
|
||||
|
||||
readable-stream@2.3.7:
|
||||
version "2.3.7"
|
||||
resolved "https://registry.npmmirror.com/readable-stream/-/readable-stream-2.3.7.tgz#1eca1cf711aef814c04f62252a36a62f6cb23b57"
|
||||
integrity sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==
|
||||
dependencies:
|
||||
core-util-is "~1.0.0"
|
||||
inherits "~2.0.3"
|
||||
isarray "~1.0.0"
|
||||
process-nextick-args "~2.0.0"
|
||||
safe-buffer "~5.1.1"
|
||||
string_decoder "~1.1.1"
|
||||
util-deprecate "~1.0.1"
|
||||
|
||||
resty-client@0.0.5:
|
||||
version "0.0.5"
|
||||
resolved "https://registry.npmmirror.com/resty-client/-/resty-client-0.0.5.tgz#f98e143fd824e5844d46c47e11c81567e58fac07"
|
||||
@ -79,6 +137,28 @@ resty-client@0.0.5:
|
||||
dependencies:
|
||||
axios ">=0.21.1"
|
||||
|
||||
safe-buffer@5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
|
||||
version "5.1.2"
|
||||
resolved "https://registry.npmmirror.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
|
||||
integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==
|
||||
|
||||
sqlstring@2.3.1:
|
||||
version "2.3.1"
|
||||
resolved "https://registry.npmmirror.com/sqlstring/-/sqlstring-2.3.1.tgz#475393ff9e91479aea62dcaf0ca3d14983a7fb40"
|
||||
integrity sha512-ooAzh/7dxIG5+uDik1z/Rd1vli0+38izZhGzSa34FwR7IbelPWCCKSNIl8jlL/F7ERvy8CB2jNeM1E9i9mXMAQ==
|
||||
|
||||
string_decoder@~1.1.1:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.npmmirror.com/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8"
|
||||
integrity sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==
|
||||
dependencies:
|
||||
safe-buffer "~5.1.0"
|
||||
|
||||
util-deprecate@~1.0.1:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.npmmirror.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
|
||||
integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==
|
||||
|
||||
ws@^7.4.4:
|
||||
version "7.5.8"
|
||||
resolved "https://registry.npmmirror.com/ws/-/ws-7.5.8.tgz#ac2729881ab9e7cbaf8787fe3469a48c5c7f636a"
|
||||
|
Loading…
Reference in New Issue
Block a user