add roles

This commit is contained in:
theluyuan 2022-06-07 16:24:16 +08:00
parent 26a4c93ee1
commit e502f72858
4 changed files with 583 additions and 473 deletions

View File

@ -10,4 +10,22 @@ export async function getRole(guildId) {
console.log("缓存命中") console.log("缓存命中")
return myCache.get("roleList") return myCache.get("roleList")
} }
} }
export async function getGuild(name){
let { data } = await client.meApi.meGuilds();
// return data.forEach((item)=>{
// // return
// if(item.name == name){
// return item.id
// }
// })
for(const i of data){
if(i.name == name){
return i.id
}
}
}

View File

@ -10,6 +10,7 @@
"mitt": "^3.0.0", "mitt": "^3.0.0",
"mysql": "^2.18.1", "mysql": "^2.18.1",
"node-cache": "^5.1.2", "node-cache": "^5.1.2",
"node-schedule": "^2.1.0",
"qq-guild-bot": "^2.9.4" "qq-guild-bot": "^2.9.4"
}, },
"scripts": { "scripts": {

View File

@ -1,9 +1,36 @@
import dayjs from "dayjs" import dayjs from "dayjs"
import { getRole } from "../../bin/channel-core/tools.js" import { client } from "../../bin/channel-core/base.js"
import { getGuild, getRole } from "../../bin/channel-core/tools.js"
import { onMessageCreate } from "../../bin/message/index.js" import { onMessageCreate } from "../../bin/message/index.js"
import { query } from "../../bin/mysql/base.js" import { query } from "../../bin/mysql/base.js"
import { addouter } from "../../bin/server/base.js" import { addouter } from "../../bin/server/base.js"
async function getActiveList(){
const sql = `select userid,count(*) from active where date_sub(curdate(), INTERVAL 30 DAY) <= date(activedate) GROUP BY userid`
const list = await query(sql)
console.log(list)
let user = []
for(let i of list){
if(i["count(*)"] > 2){
user.push(i.userid)
}
}
return user
}
async function setrole(){
const gid = await getGuild("web前端")
const list = await getActiveList()
console.log(list,24)
for(let i of list){
let { data } = await client.memberApi.memberAddRole(gid, "10868905", i);
}
console.log(list)
}
async function getlist(){ async function getlist(){
const list = await query("select * from active") const list = await query("select * from active")
return list return list
@ -105,6 +132,10 @@ function createMessage({msg}){
} }
onMessageCreate(createMessage) onMessageCreate(createMessage)
// getRole()
// const res = await activeCount('384023542260794903') // const res = await activeCount('384023542260794903')
// console.log(res) // console.log(res)
setrole()
init() init()

1002
yarn.lock

File diff suppressed because it is too large Load Diff