update 木鱼音频

This commit is contained in:
Yutousama 2022-11-10 20:29:49 +08:00
parent ab1facc747
commit c9eceaccf3
4 changed files with 83 additions and 30 deletions

View File

@ -12,7 +12,9 @@ import java.net.InetSocketAddress;
import java.net.Proxy; import java.net.Proxy;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map;
public class BiliBiliUtils { public class BiliBiliUtils {
private static long oldBiliBiliHttpTime = 0; private static long oldBiliBiliHttpTime = 0;
@ -64,6 +66,10 @@ public class BiliBiliUtils {
} }
public static <T> T http(String url, HTTP model, String body, RET_MODEL ret_model) { public static <T> T http(String url, HTTP model, String body, RET_MODEL ret_model) {
return http(url, model, body, null, ret_model);
}
public static <T> T http(String url, HTTP model, String body, Map<String, String> headers, RET_MODEL ret_model) {
JSONObject json = null; JSONObject json = null;
BufferedInputStream stream = null; BufferedInputStream stream = null;
ByteArrayOutputStream outputStream = null; ByteArrayOutputStream outputStream = null;
@ -81,8 +87,22 @@ public class BiliBiliUtils {
if (model == HTTP.POST) { if (model == HTTP.POST) {
connection = getBiliHttpPost(url, getCookie()); connection = getBiliHttpPost(url, getCookie());
} else { } else {
if (body != null) {
if (url.contains("?")) {
url += "&" + body;
} else {
url += "?" + body;
}
body = null;
}
connection = getBiliHttpGet(url, getCookie()); connection = getBiliHttpGet(url, getCookie());
} }
if (headers != null) {
for (String key : headers.keySet()) {
connection.setRequestProperty(key, headers.get(key));
}
}
System.out.println("url = " + url);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
if (!StringUtils.isEmpty(body)) { if (!StringUtils.isEmpty(body)) {
@ -182,7 +202,9 @@ public class BiliBiliUtils {
oldBiliBiliHttpTime = System.currentTimeMillis(); oldBiliBiliHttpTime = System.currentTimeMillis();
} }
HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection(); HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection();
if (cookie != null) {
setConnection(cookie, connection); setConnection(cookie, connection);
}
connection.setReadTimeout(5000); connection.setReadTimeout(5000);
connection.setConnectTimeout(5000); connection.setConnectTimeout(5000);
return connection; return connection;
@ -191,7 +213,7 @@ public class BiliBiliUtils {
public static File download(final String url, final String saveName, boolean isProxy) { public static File download(final String url, final String saveName, boolean isProxy) {
File jar = null; File jar = null;
try { try {
File savePath = new File(HttpTools.downloadPath+saveName); File savePath = new File(HttpTools.downloadPath + saveName);
Proxy proxy = null; Proxy proxy = null;
if (!savePath.exists()) { if (!savePath.exists()) {
savePath.mkdirs(); savePath.mkdirs();
@ -306,41 +328,45 @@ public class BiliBiliUtils {
System.out.println("sign = " + sign); System.out.println("sign = " + sign);
} }
public static boolean sendLiveDanmu(long roomId,String msg){ public static boolean sendLiveDanmu(long roomId, String msg) {
JSONObject body=new JSONObject(); JSONObject body = new JSONObject();
body.put("msg",msg); body.put("msg", msg);
body.put("roomid",roomId); body.put("roomid", roomId);
body.put("color",16777215); body.put("color", 16777215);
body.put("fontsize",25); body.put("fontsize", 25);
body.put("rnd",System.currentTimeMillis()/1000); body.put("rnd", System.currentTimeMillis() / 1000);
body.put("csrf",BiliLogin.getCookieToken()); body.put("csrf", BiliLogin.getCookieToken());
body.put("csrf_token",BiliLogin.getCookieToken()); body.put("csrf_token", BiliLogin.getCookieToken());
JSONObject post = BiliBiliUtils.http_post("https://api.live.bilibili.com/msg/send", HttpTools.toUrlParams(body)); JSONObject post = BiliBiliUtils.http_post("https://api.live.bilibili.com/msg/send", HttpTools.toUrlParams(body));
return post.getInteger("code")==0; return post.getInteger("code") == 0;
} }
public static String liveSignIn(){
public static String liveSignIn() {
//{"code":0,"data":{"coin":1,"gold":19500,"silver":106394,"tid":"Silver2Coin22101413201169763005873"},"message":"兑换成功"} //{"code":0,"data":{"coin":1,"gold":19500,"silver":106394,"tid":"Silver2Coin22101413201169763005873"},"message":"兑换成功"}
JSONObject body=new JSONObject(); JSONObject body = new JSONObject();
body.put("csrf",BiliLogin.getCookieToken()); body.put("csrf", BiliLogin.getCookieToken());
body.put("csrf_token",BiliLogin.getCookieToken()); body.put("csrf_token", BiliLogin.getCookieToken());
JSONObject post = BiliBiliUtils.http_post("https://api.live.bilibili.com/xlive/revenue/v1/wallet/silver2coin", HttpTools.toUrlParams(body)); JSONObject post = BiliBiliUtils.http_post("https://api.live.bilibili.com/xlive/revenue/v1/wallet/silver2coin", HttpTools.toUrlParams(body));
JSONObject post_ = BiliBiliUtils.http_get("https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign"); JSONObject post_ = BiliBiliUtils.http_get("https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign");
return post.getString("message")+"|"+post_.getString("message"); return post.getString("message") + "|" + post_.getString("message");
} }
public static JSONObject getLiveRoom(int roomId){
JSONObject body=new JSONObject(); public static JSONObject getLiveRoom(int roomId) {
body.put("room_id",roomId); JSONObject body = new JSONObject();
body.put("csrf",BiliLogin.getCookieToken()); body.put("room_id", roomId);
body.put("csrf_token",BiliLogin.getCookieToken()); body.put("csrf", BiliLogin.getCookieToken());
body.put("csrf_token", BiliLogin.getCookieToken());
return BiliBiliUtils.http_post("https://api.live.bilibili.com/room/v1/Room/get_info", HttpTools.toUrlParams(body)); return BiliBiliUtils.http_post("https://api.live.bilibili.com/room/v1/Room/get_info", HttpTools.toUrlParams(body));
} }
public static JSONObject getUserInfo(int mid){
JSONObject body=new JSONObject(); public static JSONObject getUserInfo(int mid) {
body.put("mid",mid); JSONObject body = new JSONObject();
return BiliBiliUtils.http_get("https://api.bilibili.com/x/space/acc/info?"+ HttpTools.toUrlParams(body)); body.put("mid", mid);
return BiliBiliUtils.http_get("https://api.bilibili.com/x/space/acc/info?" + HttpTools.toUrlParams(body));
} }
public static boolean checkLiveRoom(int roomId){
JSONObject post=getLiveRoom(roomId); public static boolean checkLiveRoom(int roomId) {
return post.getInteger("code")==0; JSONObject post = getLiveRoom(roomId);
return post.getInteger("code") == 0;
} }
} }

View File

@ -3,7 +3,15 @@ package com.yutou.qqbot.models.Commands;
import com.yutou.qqbot.Annotations.UseModel; import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.models.Model; import com.yutou.qqbot.models.Model;
import net.mamoe.mirai.contact.AudioSupported;
import net.mamoe.mirai.event.events.MessageEvent; import net.mamoe.mirai.event.events.MessageEvent;
import net.mamoe.mirai.message.data.Audio;
import net.mamoe.mirai.message.data.MessageChainBuilder;
import net.mamoe.mirai.message.data.OfflineAudio;
import net.mamoe.mirai.utils.ExternalResource;
import java.io.File;
import java.util.Objects;
import static com.yutou.qqbot.models.Model.QQGroupCommands.QQ_WOODEN; import static com.yutou.qqbot.models.Model.QQGroupCommands.QQ_WOODEN;
@ -28,6 +36,13 @@ public class WoodenFish extends Model {
public void onMessage(Long qq, MessageEvent event, boolean isGroup) { public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
super.onMessage(qq, event, isGroup); super.onMessage(qq, event, isGroup);
if(msg.contains("地狱笑话")){ if(msg.contains("地狱笑话")){
File file=new File("muyu.wav");
if(file.exists()) {
OfflineAudio audio = Objects.requireNonNull(event.getBot().getGroup(qq)).uploadAudio(ExternalResource.create(file));
MessageChainBuilder builder = new MessageChainBuilder();
builder.append(audio);
QQBotManager.getInstance().sendMessage(qq,builder);
}
QQBotManager.getInstance().sendMessage(qq,"功德+1"); QQBotManager.getInstance().sendMessage(qq,"功德+1");
} }
} }

View File

@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSON;
import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.interfaces.DownloadInterface; import com.yutou.qqbot.interfaces.DownloadInterface;
import com.yutou.qqbot.interfaces.ObjectInterface; import com.yutou.qqbot.interfaces.ObjectInterface;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
@ -231,4 +232,8 @@ public class AppTools {
return null; return null;
} }
} }
public static String getMD5(String str){
return DigestUtils.md5Hex(str);
}
} }

View File

@ -144,6 +144,13 @@ public class HttpTools {
string = new StringBuilder(string.substring(1, string.length()).replaceAll(" ", "")); string = new StringBuilder(string.substring(1, string.length()).replaceAll(" ", ""));
return string.toString(); return string.toString();
} }
public static String toUrlParams(Map<String,String> map) {
StringBuilder builder=new StringBuilder();
for (String key : map.keySet()) {
builder.append(key).append("=").append(map.get(key)).append("&");
}
return builder.substring(0, builder.length() - 1);
}
public static Map<String, String> getUrlParams(String url) { public static Map<String, String> getUrlParams(String url) {
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();