修复Linux下无法使用浏览器的问题
修复无权用户无法访问公开模块的问题
This commit is contained in:
parent
bf1492e8b0
commit
f4733ab9bc
8
pom.xml
8
pom.xml
@ -90,8 +90,10 @@
|
||||
<artifactId>selenium-java</artifactId>
|
||||
<version>3.141.59</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
@ -159,7 +161,7 @@
|
||||
|
||||
<configuration>
|
||||
<outputDirectory>
|
||||
X:\servier\tools\
|
||||
X:\servier\qqbot\
|
||||
</outputDirectory>
|
||||
|
||||
</configuration>
|
||||
|
@ -37,13 +37,13 @@ public class QQMessageListener extends SimpleListenerHost {
|
||||
new AdminMessage(qqNumber, event.getMessage().contentToString());
|
||||
}
|
||||
for (Class<?> model : Model.classList) {
|
||||
if (QQNumberManager.getManager().isUseModel(qqNumber, model)) {
|
||||
if (QQNumberManager.getManager().isUseModel(qqNumber, model)||!isGroup) {
|
||||
try {
|
||||
Model useModel = (Model) model.getDeclaredConstructor().newInstance();
|
||||
if (!useModel.isUserPublic()) {
|
||||
if (!QQNumberManager.getManager().isExistsPower(event.getSource().getFromId(), useModel.getUsePowers())) {
|
||||
Log.i("用户没有权限",event.getSource().getFromId());
|
||||
break;
|
||||
Log.i("用户没有权限",event.getSource().getFromId()+" > "+model.getSimpleName());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
useModel.onMessage(qqNumber, event, isGroup);
|
||||
|
@ -3,7 +3,7 @@ package com.yutou.qqbot.MessageEvent;
|
||||
import com.yutou.qqbot.QQBotManager;
|
||||
import com.yutou.qqbot.QQNumberManager;
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import com.yutou.qqbot.utlis.RedisTools;
|
||||
import com.yutou.qqbot.utlis.AppTools;
|
||||
import com.yutou.qqbot.utlis.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
@ -18,19 +18,18 @@ public class AdminMessage extends Message {
|
||||
private static final String MODEL_SHOW = "!查看模块";
|
||||
private static final String MODEL_DEL = "!删除模块";
|
||||
|
||||
public static final String SYSTEM_RESTART_QQ="!重启qq";
|
||||
public static final String SYSTEM_RESTART_TOOLS="!重启服务";
|
||||
|
||||
|
||||
private static final String SHOW="!列表";
|
||||
private static final String HELP="!help";
|
||||
}
|
||||
|
||||
public AdminMessage(Long qq, String msg) {
|
||||
sendQQ = qq;
|
||||
String msgSrc = msg;
|
||||
String[] msgGroup = msg.replace("!", "!").split(" ");
|
||||
|
||||
System.err.println(Model.classList.size());
|
||||
for (Class<?> aClass : Model.classList) {
|
||||
System.err.println(aClass.getName());
|
||||
}
|
||||
switch (msgGroup[0]) {
|
||||
case QQCommands.HELP -> QQBotManager.getInstance().sendMessage(qq,Model.getCommands(QQCommands.class).toString());
|
||||
case QQCommands.POWER_ADD -> {
|
||||
@ -115,13 +114,11 @@ public class AdminMessage extends Message {
|
||||
StringBuilder builder=new StringBuilder();
|
||||
for (Long user : users) {
|
||||
builder.append(user).append(":\n");
|
||||
if(QQNumberManager.getManager().isGroup(user)){
|
||||
List<String> list=QQNumberManager.getManager().getUseModel(user);
|
||||
builder.append("模块(").append(list.size()).append("):\n");
|
||||
for (String model : list) {
|
||||
List<String> modelPower=QQNumberManager.getManager().getUseModel(user);
|
||||
builder.append("模块(").append(modelPower.size()).append("):\n");
|
||||
for (String model : modelPower) {
|
||||
builder.append(model).append("\n");
|
||||
}
|
||||
}
|
||||
List<String> list=QQNumberManager.getManager().getPower(user);
|
||||
builder.append("权限(").append(list.size()).append("):\n");
|
||||
for (String power : list) {
|
||||
@ -131,6 +128,16 @@ public class AdminMessage extends Message {
|
||||
}
|
||||
QQBotManager.getInstance().sendMessage(qq,builder.toString());
|
||||
}
|
||||
case QQCommands.SYSTEM_RESTART_QQ -> {
|
||||
QQBotManager.getInstance().sendMessage(qq,"正在重启机器人");
|
||||
System.out.println("结束进程");
|
||||
AppTools.exec("cd /home/yutou/public/servier/qqbot && ./start.sh",null,true,false);
|
||||
}
|
||||
case QQCommands.SYSTEM_RESTART_TOOLS ->{
|
||||
QQBotManager.getInstance().sendMessage(qq,"正在重启服务");
|
||||
System.out.println("结束进程");
|
||||
AppTools.exec("cd /home/yutou/public/servier/tools && ./start.sh",null,true,false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class QQBotApplication {
|
||||
public static final String version="QQBot v.1.0";
|
||||
public static final String version="QQBot v.1.0.1";
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(QQBotApplication.class, args);
|
||||
RedisTools.initRedisPoolSub();
|
||||
|
36
src/main/java/com/yutou/qqbot/QQBotController.java
Normal file
36
src/main/java/com/yutou/qqbot/QQBotController.java
Normal file
@ -0,0 +1,36 @@
|
||||
package com.yutou.qqbot;
|
||||
|
||||
import com.yutou.qqbot.utlis.AppTools;
|
||||
import com.yutou.qqbot.utlis.RedisTools;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
|
||||
@Controller
|
||||
public class QQBotController {
|
||||
@ResponseBody
|
||||
@RequestMapping("/tools/openpc.do")
|
||||
public String open_pc(HttpServletRequest request, String type) {
|
||||
if ("nas".equals(type)) {
|
||||
try {
|
||||
Process process = Runtime.getRuntime().exec("wakeonlan 00:D8:61:6F:02:2F");
|
||||
RedisTools.processOut(process.getInputStream());
|
||||
RedisTools.processOut(process.getErrorStream());
|
||||
process.destroy();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/tools/server.do")
|
||||
public String sendServerManager(String title, String msg) {
|
||||
AppTools.sendServer(title, msg);
|
||||
return "ok";
|
||||
}
|
||||
}
|
@ -21,6 +21,8 @@ import java.util.Objects;
|
||||
|
||||
public class QQBotManager {
|
||||
|
||||
public static Long defGroup=891655174L;
|
||||
|
||||
static {
|
||||
Model.classList.add(QQSetu.class);
|
||||
Model.classList.add(Audio.class);
|
||||
|
@ -38,7 +38,11 @@ public class QQNumberManager {
|
||||
jedis.select(RedisTools.QQBOT_USER);
|
||||
Set<String> set=jedis.keys("*");
|
||||
for (String s : set) {
|
||||
try {
|
||||
list.add(Long.parseLong(s));
|
||||
}catch (Exception ignored){
|
||||
|
||||
}
|
||||
}
|
||||
jedis.close();
|
||||
return list;
|
||||
|
@ -88,7 +88,6 @@ public class TurnipProphet extends Model {
|
||||
json = JSONObject.parseObject(data);
|
||||
array = json.getJSONArray("turnip");
|
||||
}
|
||||
System.err.println(getDay());
|
||||
if (array.getInteger(0) == -1 && getDay() != 0) {
|
||||
QQBotManager.getInstance().sendMessage(qq, "没有周日买入信息,本周不收录 :(");
|
||||
return;
|
||||
@ -142,7 +141,14 @@ public class TurnipProphet extends Model {
|
||||
QQBotManager.getInstance().sendMessage(qq, "已记录,正在预测本周走势...");
|
||||
Map<String, String> map = WebClient.getInstance().openTurnip(prices, pattern);
|
||||
|
||||
|
||||
if (map == null) {
|
||||
String url = String.format("https://turnipprophet.io?prices=%s%s",
|
||||
prices,
|
||||
pattern == null ? "" : "&pattern=" + pattern
|
||||
);
|
||||
QQBotManager.getInstance().sendMessage(qq, "没有结果,请检查数据是否有误。 \n网页预览:" + url);
|
||||
return;
|
||||
}
|
||||
|
||||
JSONObject pr = JSONObject.parseObject(map.get(TurnipData.MODEL));
|
||||
JSONArray prArray = pr.getJSONArray(TurnipData.MODEL);
|
||||
@ -183,6 +189,7 @@ public class TurnipProphet extends Model {
|
||||
QQBotManager.getInstance().sendMessage(qq, out.toString());
|
||||
} catch (Exception e) {
|
||||
setData(money, qq);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,7 +23,6 @@ public class Bangumi extends Model {
|
||||
super.onMessage(qq, event, isGroup);
|
||||
|
||||
if(!isGroupPower){
|
||||
System.err.println(qq+" 没有权限");
|
||||
return;
|
||||
}
|
||||
switch (msg){
|
||||
@ -123,4 +122,12 @@ public class Bangumi extends Model {
|
||||
QQGroupCommands.QQ_BANGUMI_TODAY
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTime(String time) {
|
||||
super.onTime(time);
|
||||
switch (time) {
|
||||
case "08:00", "20:00" -> QQBotManager.getInstance().sendMessage(QQBotManager.defGroup,BangumiTools.reportToDayBangumi());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ public class Restart extends Model {
|
||||
super.onMessage(qq, event, isGroup);
|
||||
if(msg.equals(QQGroupCommands.QQ_SYSTEM_RESTART)){
|
||||
QQBotManager.getInstance().sendMessage(qq,"正在重启服务");
|
||||
System.out.println("结束进程");
|
||||
AppTools.exec("cd /home/yutou/public/servier/tools && ./start.sh",null,true,false);
|
||||
}
|
||||
}
|
||||
|
@ -55,12 +55,14 @@ public abstract class Model implements ModelInterface {
|
||||
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
|
||||
msg = event.getMessage().contentToString();
|
||||
msg = msg.replace("!", "!");
|
||||
if(isGroup) {
|
||||
GroupMessageEvent groupEvent = (GroupMessageEvent) event;
|
||||
group = groupEvent.getGroup().getId();
|
||||
if (QQNumberManager.getManager().isExistsPower(group, msg.split(" ")[0])) {
|
||||
isGroupPower = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onTime(String time) {
|
||||
}
|
||||
|
@ -8,10 +8,7 @@ import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.chrome.ChromeDriver;
|
||||
import org.openqa.selenium.chrome.ChromeOptions;
|
||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -31,8 +28,8 @@ public class WebClient {
|
||||
|
||||
private WebClient() {
|
||||
System.setProperty("webdriver.chrome.driver",
|
||||
"E:\\GoogleChromeDriver\\chromedriver.exe");
|
||||
java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.OFF);
|
||||
ConfigTools.load(ConfigTools.CONFIG,"chrome",String.class));
|
||||
// java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.OFF);
|
||||
}
|
||||
|
||||
public Map<String, String> openTurnip(String prices, String pattern) throws Exception {
|
||||
@ -47,11 +44,13 @@ public class WebClient {
|
||||
webDriver.get(url);
|
||||
webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
|
||||
Thread.sleep(500);
|
||||
|
||||
WebElement element = webDriver.findElement(By.id("output"));
|
||||
List<WebElement> list = element.findElements(By.tagName("tr"));
|
||||
JSONObject pr = new JSONObject();
|
||||
JSONArray array = new JSONArray();
|
||||
if(list.size()==0){
|
||||
return null;
|
||||
}
|
||||
|
||||
for (WebElement webElement : list) {
|
||||
String[] tmp;
|
||||
@ -104,7 +103,8 @@ public class WebClient {
|
||||
ChromeOptions options = new ChromeOptions();
|
||||
options.addArguments("disable-infobars");
|
||||
options.addArguments("blink-settings=imagesEnabled=false");
|
||||
options.addArguments("headless");
|
||||
options.addArguments("--headless");
|
||||
options.addArguments("--no-sandbox");
|
||||
|
||||
return options;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user