add 活跃统计
This commit is contained in:
@@ -1,35 +1,84 @@
|
||||
import dayjs from "dayjs"
|
||||
import { getRole } from "../../bin/channel-core/tools.js"
|
||||
import { onMessageCreate } from "../../bin/message/index.js"
|
||||
import { query } from "../../bin/mysql/base.js"
|
||||
|
||||
|
||||
function init(){
|
||||
|
||||
}
|
||||
|
||||
async function activeCount(userid){
|
||||
const sql = `select count(*) from active where date_sub(curdate(), INTERVAL 30 DAY) <= date(activedate);`
|
||||
const sql2 = `select * from active where date_sub(curdate(), INTERVAL 30 DAY) <= date(activedate);`
|
||||
|
||||
async function updateActive({member,author,guild_id,content}){
|
||||
const count = (await query(sql))[0]["count(*)"]
|
||||
const list = await query(sql2)
|
||||
return {
|
||||
count,
|
||||
list
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {String} userid 用户id
|
||||
* @returns Boolean true 活跃过 false 未活跃
|
||||
*/
|
||||
async function isActive(userid){
|
||||
const sql = `select * from active where userid='${userid}' and activedate='${dayjs().format("YYYY-MM-DD")}'`
|
||||
console.log(sql)
|
||||
const res = await query(sql)
|
||||
console.log(res)
|
||||
if(res.length == 0){
|
||||
return false
|
||||
}else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {object} param0 {member当前频道用户信息对象,author用户频道信息对象,guild_id频道id,content消息内容}
|
||||
*
|
||||
* @returns null
|
||||
*/
|
||||
|
||||
async function updateActive({member,author,guild_id,content}){5
|
||||
const jointime = dayjs(member.joined_at).format('YYYY-MM-DD HH:mm:ss')
|
||||
// console.log(time.format('YYYY-MM-DD HH:mm:ss'))
|
||||
const nickname = member.nick
|
||||
const roles = []
|
||||
const roles = JSON.stringify(member.roles)
|
||||
const avatar = author.avatar
|
||||
const id = author.id
|
||||
const bot = author.bot
|
||||
const userid = author.id
|
||||
const bot = author.bot ? 1 : 0
|
||||
const username = author.username
|
||||
// const roleList = await getRole(guild_id)
|
||||
// const content = content
|
||||
// console.log(roleList)
|
||||
const info = {
|
||||
jointime,
|
||||
nickname,
|
||||
avatar,
|
||||
id,
|
||||
userid,
|
||||
bot,
|
||||
username,
|
||||
content
|
||||
content,
|
||||
roles,
|
||||
date: dayjs().format("YYYY-MM-DD")
|
||||
}
|
||||
console.log(info)
|
||||
|
||||
// console.log(info)
|
||||
const isactive = await isActive(info.userid)
|
||||
if(isactive){
|
||||
console.log("今日活跃 跳过")
|
||||
return ;
|
||||
}
|
||||
const sql = `insert into active value(null,'${info.nickname}','${info.avatar}','${info.userid}',${info.bot},'${info.username}','${roles}','${info.jointime}','${info.date}')`
|
||||
try{
|
||||
await query(sql)
|
||||
}catch{
|
||||
console.log("activeStatistics inset error")
|
||||
}
|
||||
|
||||
// console.log(res)
|
||||
}
|
||||
|
||||
|
||||
@@ -41,4 +90,7 @@ function createMessage({msg}){
|
||||
console.log("收到消息",msg)
|
||||
updateActive(msg)
|
||||
}
|
||||
onMessageCreate(createMessage)
|
||||
onMessageCreate(createMessage)
|
||||
|
||||
const res = await activeCount()
|
||||
console.log(res)
|
||||
Reference in New Issue
Block a user