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.URL;
import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class BiliBiliUtils {
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) {
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;
BufferedInputStream stream = null;
ByteArrayOutputStream outputStream = null;
@ -81,8 +87,22 @@ public class BiliBiliUtils {
if (model == HTTP.POST) {
connection = getBiliHttpPost(url, getCookie());
} else {
if (body != null) {
if (url.contains("?")) {
url += "&" + body;
} else {
url += "?" + body;
}
body = null;
}
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");
if (!StringUtils.isEmpty(body)) {
@ -182,7 +202,9 @@ public class BiliBiliUtils {
oldBiliBiliHttpTime = System.currentTimeMillis();
}
HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection();
setConnection(cookie, connection);
if (cookie != null) {
setConnection(cookie, connection);
}
connection.setReadTimeout(5000);
connection.setConnectTimeout(5000);
return connection;
@ -191,7 +213,7 @@ public class BiliBiliUtils {
public static File download(final String url, final String saveName, boolean isProxy) {
File jar = null;
try {
File savePath = new File(HttpTools.downloadPath+saveName);
File savePath = new File(HttpTools.downloadPath + saveName);
Proxy proxy = null;
if (!savePath.exists()) {
savePath.mkdirs();
@ -230,7 +252,7 @@ public class BiliBiliUtils {
}
jar.renameTo(oldJar);
Log.i("DOWNLOAD", "实际保存:" + oldJar.getAbsolutePath() + " " + oldJar.getName());
return oldJar;
return oldJar;
} catch (Exception e) {
e.printStackTrace();
if (jar != null) {
@ -306,41 +328,45 @@ public class BiliBiliUtils {
System.out.println("sign = " + sign);
}
public static boolean sendLiveDanmu(long roomId,String msg){
JSONObject body=new JSONObject();
body.put("msg",msg);
body.put("roomid",roomId);
body.put("color",16777215);
body.put("fontsize",25);
body.put("rnd",System.currentTimeMillis()/1000);
body.put("csrf",BiliLogin.getCookieToken());
body.put("csrf_token",BiliLogin.getCookieToken());
public static boolean sendLiveDanmu(long roomId, String msg) {
JSONObject body = new JSONObject();
body.put("msg", msg);
body.put("roomid", roomId);
body.put("color", 16777215);
body.put("fontsize", 25);
body.put("rnd", System.currentTimeMillis() / 1000);
body.put("csrf", BiliLogin.getCookieToken());
body.put("csrf_token", BiliLogin.getCookieToken());
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":"兑换成功"}
JSONObject body=new JSONObject();
body.put("csrf",BiliLogin.getCookieToken());
body.put("csrf_token",BiliLogin.getCookieToken());
JSONObject body = new JSONObject();
body.put("csrf", 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_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();
body.put("room_id",roomId);
body.put("csrf",BiliLogin.getCookieToken());
body.put("csrf_token",BiliLogin.getCookieToken());
public static JSONObject getLiveRoom(int roomId) {
JSONObject body = new JSONObject();
body.put("room_id", roomId);
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));
}
public static JSONObject getUserInfo(int mid){
JSONObject body=new JSONObject();
body.put("mid",mid);
return BiliBiliUtils.http_get("https://api.bilibili.com/x/space/acc/info?"+ HttpTools.toUrlParams(body));
public static JSONObject getUserInfo(int mid) {
JSONObject body = new JSONObject();
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);
return post.getInteger("code")==0;
public static boolean checkLiveRoom(int roomId) {
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.QQBotManager;
import com.yutou.qqbot.models.Model;
import net.mamoe.mirai.contact.AudioSupported;
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;
@ -28,6 +36,13 @@ public class WoodenFish extends Model {
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
super.onMessage(qq, event, isGroup);
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");
}
}

View File

@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSON;
import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.interfaces.DownloadInterface;
import com.yutou.qqbot.interfaces.ObjectInterface;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
@ -231,4 +232,8 @@ public class AppTools {
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(" ", ""));
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) {
Map<String, String> map = new HashMap<>();