Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
dullwolf committed Jun 3, 2022
1 parent 7e4f3ba commit 48237d9
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/las/cmd/admin/ResetFun.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void execute(Long userId, Long id, Integer type, String command, ArrayLis
if (null != userId) {
long superQQ = Long.parseLong(AppConfigs.SUPER_QQ);
if (userId != superQQ) {
CmdUtil.sendMessage("必须是超管才可以更新机器人权限", userId, id, type);
CmdUtil.sendMessage("必须是超管才可以更新机器人功能", userId, id, type);
} else {
initBotFun();
CmdUtil.sendMessage("更新成功", userId, id, type);
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/com/las/cmd/admin/ResetGp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.las.cmd.admin;

import cn.hutool.core.collection.CollectionUtil;
import com.las.annotation.BotCmd;
import com.las.cmd.Command;
import com.las.common.Constant;
import com.las.config.AppConfigs;
import com.las.model.GroupExt;
import com.las.utils.CmdUtil;
import org.apache.log4j.Logger;

import java.util.ArrayList;

@BotCmd(funName = "超管功能", funWeight = 999)
public class ResetGp extends Command {

private static Logger logger = Logger.getLogger(ResetGp.class);


public ResetGp() {
super("群设置", "GP");
}

@Override
public void execute(Long userId, Long id, Integer type, String command, ArrayList<String> args) throws Exception {
long superQQ = Long.parseLong(AppConfigs.SUPER_QQ);
if (userId != superQQ) {
CmdUtil.sendMessage("必须是超管才可以设置群配置", userId, id, type);
} else {
if (Constant.MESSAGE_TYPE_GROUP == type) {
if (CollectionUtil.isNotEmpty(args)) {
// 获得前缀
String prefix = args.get(0).trim();
if ("空".equals(prefix) || "None".equalsIgnoreCase(prefix)) {
prefix = "";
}
GroupExt groupExt = getGroupExtDao().findByGid(id);
if (null != groupExt) {
groupExt.setAttribute2(prefix);
}
getGroupExtDao().saveOrUpdate(groupExt);
CmdUtil.sendMessage("更新成功", userId, id, type);
}
}
}
}
}
36 changes: 23 additions & 13 deletions src/main/java/com/las/cmd/admin/ResetWeight.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ResetWeight extends Command {


public ResetWeight() {
super("权限赋能", "WeightUp");
super("权限赋能", "权限更新");
}

@Override
Expand All @@ -28,25 +28,35 @@ public void execute(Long userId, Long id, Integer type, String command, ArrayLis
if (userId != superQQ) {
CmdUtil.sendMessage("必须是超管才可以更新机器人权限", userId, id, type);
} else {
// 给用户设置权限 1~995
// 996、997、998 分别是普通管理员、中级管理员、高级管理员
if (args.size() == 2) {
// 必须只传两个参数,例如 权限赋能 用户QQ号 权限值
String qq = args.get(0);
String weight = args.get(1);
if (StrUtils.isNumeric(qq) && StrUtils.isNumeric(weight)) {
User qqUser = getUserDao().findByUid(Long.parseLong(qq));
if (null == qqUser) {
// 数据库不存在,直接创建
qqUser = new User();
qqUser.setRemark("初次初始化权限赋能");
User qqUser = null;
if (command.startsWith("权限赋能") && Integer.parseInt(weight) > 995) {
// 权限赋能 996、997、998 分别是普通管理员、中级管理员、高级管理员
qqUser = getUserDao().findGroupUser(Long.parseLong(qq));
if (null == qqUser) {
// 数据库不存在,直接创建并且一定要设置备注
qqUser = new User();
qqUser.setRemark("初次初始化权限赋能");
}
} else if (command.startsWith("权限更新") && Integer.parseInt(weight) < 996) {
// 权限更新 是给用户设置权限 1~995
qqUser = getUserDao().findByUid(Long.parseLong(qq));
if (null == qqUser) {
qqUser = new User();
}
}
if (null != qqUser) {
qqUser.setBotQQ(Long.parseLong(AppConfigs.BOT_QQ));
qqUser.setUserId(Long.parseLong(qq));
qqUser.setFunPermission(Integer.parseInt(weight));
getUserDao().saveOrUpdate(qqUser);
CmdUtil.sendMessage("更新成功", userId, id, type);
}
qqUser.setBotQQ(Long.parseLong(AppConfigs.BOT_QQ));
qqUser.setUserId(Long.parseLong(qq));
qqUser.setFunPermission(Integer.parseInt(weight));
getUserDao().saveOrUpdate(qqUser);
}
CmdUtil.sendMessage("更新成功", userId, id, type);
}
}
}
Expand Down
23 changes: 15 additions & 8 deletions src/main/java/com/las/cmd/group/GroupJoinTip.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.las.annotation.BotCmd;
import com.las.cmd.Command;
import com.las.common.Constant;
import com.las.model.GroupExt;
import com.las.utils.CmdUtil;
import com.las.utils.StrUtils;
Expand All @@ -12,20 +13,26 @@
public class GroupJoinTip extends Command {

public GroupJoinTip() {
super("群欢迎设置", "groupTip");
super("群欢迎设置", "groupTip","gt");
}

@Override
public void execute(Long userId, Long id, Integer type, String command, ArrayList<String> args) throws Exception {
if (args.size() == 2) {
// 必须只传两个参数,例如 群欢迎设置 群号 欢迎提示(带“空”字表示取消)
String gId = args.get(0);
String tip = args.get(1);
if (StrUtils.isNumeric(gId) && StrUtils.isNotEmpty(tip)) {
if ("空".equals(tip) || "None".equalsIgnoreCase(tip)) {
if (Constant.MESSAGE_TYPE_GROUP == type) {
// 必须是在群里使用,例如 群欢迎设置 欢迎提示(带“空”字表示取消)
String tip = null;
if (args.size() > 0) {
StringBuilder sb = new StringBuilder();
for (String s : args) {
sb.append(s).append(" ");
}
tip = sb.toString();
}
if (StrUtils.isNotEmpty(tip)) {
if ("空".equals(tip.trim()) || "None".equalsIgnoreCase(tip.trim())) {
tip = "";
}
GroupExt groupExt = getGroupExtDao().findByGid(Long.parseLong(gId));
GroupExt groupExt = getGroupExtDao().findByGid(id);
if (null != groupExt) {
groupExt.setAttribute1(tip);
getGroupExtDao().saveOrUpdate(groupExt);
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/com/las/dao/UserDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,32 @@ public User findSuperQQ() throws Exception {
/**
* 根据用户QQ查找一条记录
*
* ps:排除初次初始化权限赋能的,因为群管理员和普通用户用同一个权限字段 fun_weight,
* 只能通过remark区分,大部分企业公司都是用这招的!!
*
* @param uid 用户QQ
* @return User
*/
public User findByUid(Long uid) {
String sql = "select * from `user` where user_id = ? and bot_qq = ?";
String sql = "select * from `user` where user_id = ? and bot_qq = ? and remark <> '初次初始化权限赋能'";
User user = null;
try {
user = getRunner().query(sql, new BeanHandler<>(User.class, getProcessor()), uid, Long.parseLong(AppConfigs.BOT_QQ));
} catch (SQLException e) {
e.printStackTrace();
}
return user;
}

/**
*
* 查找用户是否是群管理员,权限有996、997、998
*
* @param uid 用户QQ
* @return User
*/
public User findGroupUser(Long uid) {
String sql = "select * from `user` where user_id = ? and bot_qq = ? and remark = '初次初始化权限赋能'";
User user = null;
try {
user = getRunner().query(sql, new BeanHandler<>(User.class, getProcessor()), uid, Long.parseLong(AppConfigs.BOT_QQ));
Expand Down
22 changes: 17 additions & 5 deletions src/main/java/com/las/strategy/handle/BotMsgHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,23 @@ private boolean checkExe(Long userId, Long id, int type, BotCmd botCmd) {
if (AppConfigs.SUPER_QQ.equals(userId.toString())) {
user.setFunPermission(Constant.SUPER_PERMISSION);
} else {
if (user.getFunPermission() < funWeight) {
isExecute = false;
// 用户权限小于功能权限,则返回错误信息(非匹配指令不需要)
if (botCmd.isMatch()) {
logger.warn("用户:" + userId + " 权限不足,请联系管理员");
if (funWeight < 996) {
if (user.getFunPermission() < funWeight) {
isExecute = false;
// 用户权限小于功能权限,则返回错误信息(非匹配指令不需要)
if (botCmd.isMatch()) {
logger.warn("用户:" + userId + " 权限不足,请联系管理员");
}
}
} else {
// 管理员的功能需要查找管理员初始用户
User groupUser = getUserDao().findGroupUser(userId);
if (null == groupUser || groupUser.getFunPermission() < funWeight) {
isExecute = false;
// 用户权限小于功能权限,则返回错误信息(非匹配指令不需要)
if (botCmd.isMatch()) {
logger.warn("群管:" + userId + " 权限不足,请联系超管");
}
}
}
}
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/com/las/strategy/handle/MemberJoinMsgHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.las.strategy.handle;

import com.alibaba.fastjson.JSONObject;
import com.las.common.Constant;
import com.las.model.GroupExt;
import com.las.utils.CmdUtil;
Expand All @@ -9,13 +10,14 @@ public class MemberJoinMsgHandler extends BotMsgHandler {

@Override
public void exec() {
if (Constant.MESSAGE_TYPE_GROUP == getMsgType()) {
GroupExt groupExt = getGroupExtDao().findByGid(getId());
String tip = groupExt.getAttribute1();
// 若欢迎提示不为空,则欢迎新人入群
if (StrUtils.isNotBlank(tip)) {
CmdUtil.sendAtMessage(tip, getUserId(), getUserId(), getId(), getMsgType());
}
JSONObject member = getMsgObject().getJSONObject("member");
Long gId = member.getJSONObject("group").getLong("id");
Long uId = member.getLong("id");
GroupExt groupExt = getGroupExtDao().findByGid(gId);
String tip = groupExt.getAttribute1();
// 若欢迎提示不为空,则欢迎新人入群
if (StrUtils.isNotBlank(tip)) {
CmdUtil.sendAtMessage(tip, uId, uId, gId, Constant.MESSAGE_TYPE_GROUP);
}
}

Expand Down

0 comments on commit 48237d9

Please sign in to comment.