修复Linux下无法使用浏览器的问题
修复无权用户无法访问公开模块的问题
This commit is contained in:
parent
bf1492e8b0
commit
f4733ab9bc
8
pom.xml
8
pom.xml
@ -90,8 +90,10 @@
|
|||||||
<artifactId>selenium-java</artifactId>
|
<artifactId>selenium-java</artifactId>
|
||||||
<version>3.141.59</version>
|
<version>3.141.59</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@ -159,7 +161,7 @@
|
|||||||
|
|
||||||
<configuration>
|
<configuration>
|
||||||
<outputDirectory>
|
<outputDirectory>
|
||||||
X:\servier\tools\
|
X:\servier\qqbot\
|
||||||
</outputDirectory>
|
</outputDirectory>
|
||||||
|
|
||||||
</configuration>
|
</configuration>
|
||||||
|
@ -37,13 +37,13 @@ public class QQMessageListener extends SimpleListenerHost {
|
|||||||
new AdminMessage(qqNumber, event.getMessage().contentToString());
|
new AdminMessage(qqNumber, event.getMessage().contentToString());
|
||||||
}
|
}
|
||||||
for (Class<?> model : Model.classList) {
|
for (Class<?> model : Model.classList) {
|
||||||
if (QQNumberManager.getManager().isUseModel(qqNumber, model)) {
|
if (QQNumberManager.getManager().isUseModel(qqNumber, model)||!isGroup) {
|
||||||
try {
|
try {
|
||||||
Model useModel = (Model) model.getDeclaredConstructor().newInstance();
|
Model useModel = (Model) model.getDeclaredConstructor().newInstance();
|
||||||
if (!useModel.isUserPublic()) {
|
if (!useModel.isUserPublic()) {
|
||||||
if (!QQNumberManager.getManager().isExistsPower(event.getSource().getFromId(), useModel.getUsePowers())) {
|
if (!QQNumberManager.getManager().isExistsPower(event.getSource().getFromId(), useModel.getUsePowers())) {
|
||||||
Log.i("用户没有权限",event.getSource().getFromId());
|
Log.i("用户没有权限",event.getSource().getFromId()+" > "+model.getSimpleName());
|
||||||
break;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
useModel.onMessage(qqNumber, event, isGroup);
|
useModel.onMessage(qqNumber, event, isGroup);
|
||||||
|
@ -3,7 +3,7 @@ package com.yutou.qqbot.MessageEvent;
|
|||||||
import com.yutou.qqbot.QQBotManager;
|
import com.yutou.qqbot.QQBotManager;
|
||||||
import com.yutou.qqbot.QQNumberManager;
|
import com.yutou.qqbot.QQNumberManager;
|
||||||
import com.yutou.qqbot.models.Model;
|
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 com.yutou.qqbot.utlis.StringUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -18,19 +18,18 @@ public class AdminMessage extends Message {
|
|||||||
private static final String MODEL_SHOW = "!查看模块";
|
private static final String MODEL_SHOW = "!查看模块";
|
||||||
private static final String MODEL_DEL = "!删除模块";
|
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 SHOW="!列表";
|
||||||
private static final String HELP="!help";
|
private static final String HELP="!help";
|
||||||
}
|
}
|
||||||
|
|
||||||
public AdminMessage(Long qq, String msg) {
|
public AdminMessage(Long qq, String msg) {
|
||||||
sendQQ = qq;
|
sendQQ = qq;
|
||||||
String msgSrc = msg;
|
|
||||||
String[] msgGroup = msg.replace("!", "!").split(" ");
|
String[] msgGroup = msg.replace("!", "!").split(" ");
|
||||||
|
|
||||||
System.err.println(Model.classList.size());
|
|
||||||
for (Class<?> aClass : Model.classList) {
|
|
||||||
System.err.println(aClass.getName());
|
|
||||||
}
|
|
||||||
switch (msgGroup[0]) {
|
switch (msgGroup[0]) {
|
||||||
case QQCommands.HELP -> QQBotManager.getInstance().sendMessage(qq,Model.getCommands(QQCommands.class).toString());
|
case QQCommands.HELP -> QQBotManager.getInstance().sendMessage(qq,Model.getCommands(QQCommands.class).toString());
|
||||||
case QQCommands.POWER_ADD -> {
|
case QQCommands.POWER_ADD -> {
|
||||||
@ -115,12 +114,10 @@ public class AdminMessage extends Message {
|
|||||||
StringBuilder builder=new StringBuilder();
|
StringBuilder builder=new StringBuilder();
|
||||||
for (Long user : users) {
|
for (Long user : users) {
|
||||||
builder.append(user).append(":\n");
|
builder.append(user).append(":\n");
|
||||||
if(QQNumberManager.getManager().isGroup(user)){
|
List<String> modelPower=QQNumberManager.getManager().getUseModel(user);
|
||||||
List<String> list=QQNumberManager.getManager().getUseModel(user);
|
builder.append("模块(").append(modelPower.size()).append("):\n");
|
||||||
builder.append("模块(").append(list.size()).append("):\n");
|
for (String model : modelPower) {
|
||||||
for (String model : list) {
|
builder.append(model).append("\n");
|
||||||
builder.append(model).append("\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
List<String> list=QQNumberManager.getManager().getPower(user);
|
List<String> list=QQNumberManager.getManager().getPower(user);
|
||||||
builder.append("权限(").append(list.size()).append("):\n");
|
builder.append("权限(").append(list.size()).append("):\n");
|
||||||
@ -131,6 +128,16 @@ public class AdminMessage extends Message {
|
|||||||
}
|
}
|
||||||
QQBotManager.getInstance().sendMessage(qq,builder.toString());
|
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
|
@SpringBootApplication
|
||||||
public class QQBotApplication {
|
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) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(QQBotApplication.class, args);
|
SpringApplication.run(QQBotApplication.class, args);
|
||||||
RedisTools.initRedisPoolSub();
|
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 class QQBotManager {
|
||||||
|
|
||||||
|
public static Long defGroup=891655174L;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Model.classList.add(QQSetu.class);
|
Model.classList.add(QQSetu.class);
|
||||||
Model.classList.add(Audio.class);
|
Model.classList.add(Audio.class);
|
||||||
|
@ -38,7 +38,11 @@ public class QQNumberManager {
|
|||||||
jedis.select(RedisTools.QQBOT_USER);
|
jedis.select(RedisTools.QQBOT_USER);
|
||||||
Set<String> set=jedis.keys("*");
|
Set<String> set=jedis.keys("*");
|
||||||
for (String s : set) {
|
for (String s : set) {
|
||||||
|
try {
|
||||||
list.add(Long.parseLong(s));
|
list.add(Long.parseLong(s));
|
||||||
|
}catch (Exception ignored){
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
jedis.close();
|
jedis.close();
|
||||||
return list;
|
return list;
|
||||||
|
@ -88,9 +88,8 @@ public class TurnipProphet extends Model {
|
|||||||
json = JSONObject.parseObject(data);
|
json = JSONObject.parseObject(data);
|
||||||
array = json.getJSONArray("turnip");
|
array = json.getJSONArray("turnip");
|
||||||
}
|
}
|
||||||
System.err.println(getDay());
|
if (array.getInteger(0) == -1 && getDay() != 0) {
|
||||||
if(array.getInteger(0)==-1&&getDay()!=0){
|
QQBotManager.getInstance().sendMessage(qq, "没有周日买入信息,本周不收录 :(");
|
||||||
QQBotManager.getInstance().sendMessage(qq,"没有周日买入信息,本周不收录 :(");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (json.containsKey("old_pattern")) {
|
if (json.containsKey("old_pattern")) {
|
||||||
@ -131,18 +130,25 @@ public class TurnipProphet extends Model {
|
|||||||
prices = prices.replace("-1", "");
|
prices = prices.replace("-1", "");
|
||||||
json.put("prices", prices);
|
json.put("prices", prices);
|
||||||
try {
|
try {
|
||||||
if(pattern!=null) {
|
if (pattern != null) {
|
||||||
switch (pattern){
|
switch (pattern) {
|
||||||
case "波动型" -> pattern="0";
|
case "波动型" -> pattern = "0";
|
||||||
case "大幅上涨(三期型)"-> pattern="1";
|
case "大幅上涨(三期型)" -> pattern = "1";
|
||||||
case "递减型" -> pattern="2";
|
case "递减型" -> pattern = "2";
|
||||||
case "小幅上涨(四期型)" -> pattern="3";
|
case "小幅上涨(四期型)" -> pattern = "3";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QQBotManager.getInstance().sendMessage(qq,"已记录,正在预测本周走势...");
|
QQBotManager.getInstance().sendMessage(qq, "已记录,正在预测本周走势...");
|
||||||
Map<String, String> map = WebClient.getInstance().openTurnip(prices, pattern);
|
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));
|
JSONObject pr = JSONObject.parseObject(map.get(TurnipData.MODEL));
|
||||||
JSONArray prArray = pr.getJSONArray(TurnipData.MODEL);
|
JSONArray prArray = pr.getJSONArray(TurnipData.MODEL);
|
||||||
@ -179,10 +185,11 @@ public class TurnipProphet extends Model {
|
|||||||
out.append("祝好运 :)");
|
out.append("祝好运 :)");
|
||||||
json.put("pattern", prArray.getJSONObject(0).getString(TurnipData.MODEL));
|
json.put("pattern", prArray.getJSONObject(0).getString(TurnipData.MODEL));
|
||||||
RedisTools.set(redisKey, json.toJSONString());
|
RedisTools.set(redisKey, json.toJSONString());
|
||||||
Log.i("TurnipProphet",out.toString());
|
Log.i("TurnipProphet", out.toString());
|
||||||
QQBotManager.getInstance().sendMessage(qq,out.toString());
|
QQBotManager.getInstance().sendMessage(qq, out.toString());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
setData(money, qq);
|
setData(money, qq);
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -195,7 +202,7 @@ public class TurnipProphet extends Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int getDay() {
|
private int getDay() {
|
||||||
return Calendar.getInstance().get(Calendar.DAY_OF_WEEK)-1;
|
return Calendar.getInstance().get(Calendar.DAY_OF_WEEK) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
@ -23,7 +23,6 @@ public class Bangumi extends Model {
|
|||||||
super.onMessage(qq, event, isGroup);
|
super.onMessage(qq, event, isGroup);
|
||||||
|
|
||||||
if(!isGroupPower){
|
if(!isGroupPower){
|
||||||
System.err.println(qq+" 没有权限");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (msg){
|
switch (msg){
|
||||||
@ -123,4 +122,12 @@ public class Bangumi extends Model {
|
|||||||
QQGroupCommands.QQ_BANGUMI_TODAY
|
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);
|
super.onMessage(qq, event, isGroup);
|
||||||
if(msg.equals(QQGroupCommands.QQ_SYSTEM_RESTART)){
|
if(msg.equals(QQGroupCommands.QQ_SYSTEM_RESTART)){
|
||||||
QQBotManager.getInstance().sendMessage(qq,"正在重启服务");
|
QQBotManager.getInstance().sendMessage(qq,"正在重启服务");
|
||||||
System.out.println("结束进程");
|
|
||||||
AppTools.exec("cd /home/yutou/public/servier/tools && ./start.sh",null,true,false);
|
AppTools.exec("cd /home/yutou/public/servier/tools && ./start.sh",null,true,false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,10 +55,12 @@ public abstract class Model implements ModelInterface {
|
|||||||
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
|
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
|
||||||
msg = event.getMessage().contentToString();
|
msg = event.getMessage().contentToString();
|
||||||
msg = msg.replace("!", "!");
|
msg = msg.replace("!", "!");
|
||||||
GroupMessageEvent groupEvent = (GroupMessageEvent) event;
|
if(isGroup) {
|
||||||
group = groupEvent.getGroup().getId();
|
GroupMessageEvent groupEvent = (GroupMessageEvent) event;
|
||||||
if (QQNumberManager.getManager().isExistsPower(group, msg.split(" ")[0])) {
|
group = groupEvent.getGroup().getId();
|
||||||
isGroupPower = true;
|
if (QQNumberManager.getManager().isExistsPower(group, msg.split(" ")[0])) {
|
||||||
|
isGroupPower = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,10 +8,7 @@ import org.openqa.selenium.WebDriver;
|
|||||||
import org.openqa.selenium.WebElement;
|
import org.openqa.selenium.WebElement;
|
||||||
import org.openqa.selenium.chrome.ChromeDriver;
|
import org.openqa.selenium.chrome.ChromeDriver;
|
||||||
import org.openqa.selenium.chrome.ChromeOptions;
|
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.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -31,8 +28,8 @@ public class WebClient {
|
|||||||
|
|
||||||
private WebClient() {
|
private WebClient() {
|
||||||
System.setProperty("webdriver.chrome.driver",
|
System.setProperty("webdriver.chrome.driver",
|
||||||
"E:\\GoogleChromeDriver\\chromedriver.exe");
|
ConfigTools.load(ConfigTools.CONFIG,"chrome",String.class));
|
||||||
java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.OFF);
|
// java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> openTurnip(String prices, String pattern) throws Exception {
|
public Map<String, String> openTurnip(String prices, String pattern) throws Exception {
|
||||||
@ -47,11 +44,13 @@ public class WebClient {
|
|||||||
webDriver.get(url);
|
webDriver.get(url);
|
||||||
webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
|
webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
|
|
||||||
WebElement element = webDriver.findElement(By.id("output"));
|
WebElement element = webDriver.findElement(By.id("output"));
|
||||||
List<WebElement> list = element.findElements(By.tagName("tr"));
|
List<WebElement> list = element.findElements(By.tagName("tr"));
|
||||||
JSONObject pr = new JSONObject();
|
JSONObject pr = new JSONObject();
|
||||||
JSONArray array = new JSONArray();
|
JSONArray array = new JSONArray();
|
||||||
|
if(list.size()==0){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
for (WebElement webElement : list) {
|
for (WebElement webElement : list) {
|
||||||
String[] tmp;
|
String[] tmp;
|
||||||
@ -104,7 +103,8 @@ public class WebClient {
|
|||||||
ChromeOptions options = new ChromeOptions();
|
ChromeOptions options = new ChromeOptions();
|
||||||
options.addArguments("disable-infobars");
|
options.addArguments("disable-infobars");
|
||||||
options.addArguments("blink-settings=imagesEnabled=false");
|
options.addArguments("blink-settings=imagesEnabled=false");
|
||||||
options.addArguments("headless");
|
options.addArguments("--headless");
|
||||||
|
options.addArguments("--no-sandbox");
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user