Skip to content

Commit 5e02c53

Browse files
committed
更新参考样式模板
1 parent 33fe391 commit 5e02c53

File tree

4 files changed

+48
-17
lines changed

4 files changed

+48
-17
lines changed

BiliApi.Net

OpenDanmaki/OpenDanmaki.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class OpenDanmaki
2222
public DanmakuApi BiliDanmaku;
2323
public PluginLoader Pluginloader;
2424
public TmpResourceProvider TmpResourceProvider;
25+
public GiftResourcesProvider GiftResourcesProvider;
26+
public static Config Config { get; set; }
2527

2628
/// <summary>
2729
/// 在弹幕事件(包含sc、礼物等)接收后、被处理前触发
@@ -64,15 +66,19 @@ public OpenDanmaki(int liveroomid, string logincookie = "", string host = "local
6466
BiliDanmaku = new DanmakuApi(liveroomid, logincookie);
6567
Pluginloader = new PluginLoader(this);
6668
TmpResourceProvider = new TmpResourceProvider("http://" + host + ":" + port + "/attachments/");
69+
GiftResourcesProvider = new GiftResourcesProvider("http://" + host + ":" + port + "/");
6770
BiliDanmaku.DanmakuMsgReceivedEvent += BiliDanmaku_DanmakuMsgReceivedEvent;
6871
BiliDanmaku.CommentReceived += BiliDanmaku_CommentReceived;
6972
BiliDanmaku.Superchat += BiliDanmaku_Superchat;
7073
BiliDanmaku.Gift += BiliDanmaku_Gift;
7174
BiliDanmaku.GuardBuy += BiliDanmaku_GuardBuy;
7275
}
73-
7476

75-
public OpenDanmaki(Config config) : this(config.TargetRoomId, config.BiliCookie, config.LocalHostname, config.LocalPort) { }
77+
78+
public OpenDanmaki(Config config) : this(config.TargetRoomId, config.BiliCookie, config.LocalHostname, config.LocalPort)
79+
{
80+
Config = config;
81+
}
7682

7783
private void BiliDanmaku_DanmakuMsgReceivedEvent(object sender, DanmakuReceivedEventArgs e)
7884
{
@@ -135,12 +141,17 @@ private void BiliDanmaku_CommentReceived(object sender, BiliveDanmakuAgent.Model
135141

136142
public async Task StartAsync()
137143
{
144+
Directory.CreateDirectory("./plugins");
145+
Directory.CreateDirectory("./visual_assets/emoji");
146+
Directory.CreateDirectory("./visual_assets/gifts");
138147
await Server.StartAsync();
139148
await BiliDanmaku.ConnectAsync();
140149
var ver = Assembly.GetExecutingAssembly().GetName().Version;
150+
logger.Debug("OpenDanmaki is preloading gift resources list...");
151+
var cnt = GiftResourcesProvider.LoadGiftResourcesList(Config);
152+
logger.Debug("Loaded " + cnt + " gift resource url.");
141153
logger.Info("OpenDanmaki " + ver.ToString() + " loaded.");
142154
logger.Info("Start loading plugins...");
143-
Directory.CreateDirectory("plugins");
144155
Directory.GetFiles("plugins").ToList().ForEach(x =>
145156
{
146157
if (x.ToLower().EndsWith(".odp.dll"))

OpenDanmaki/visual_assets/kboard/kboard.html

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
}
7474
}
7575

76-
.chat-message img {
76+
.avatar {
7777
width: 50px;
7878
height: 50px;
7979
border-radius: 50%;
@@ -136,6 +136,7 @@
136136
message.className = 'chat-message';
137137

138138
var img = document.createElement('img');
139+
img.classList.add('avatar');
139140
img.src = avatar; // Replace with actual avatar URL
140141

141142
var bubble = document.createElement('div');
@@ -159,8 +160,10 @@
159160

160161
var text = document.createElement('div');
161162

162-
text.innerHTML = messagetxt.toString().replace(/\[img:(.*?)\]/g, function (match, url) {
163-
return '<img src="' + url + '" style="width: 1.5em; height: 1.5em;">';
163+
text.innerHTML = messagetxt.toString().replace(/\[emoj:(.*?)\]/g, function (match, url) {
164+
return '<img src="' + url + '" style="height: 1.5em;">';
165+
}).replace(/\[img:(.*?)\]/g, function (match, url) {
166+
return '<img src="' + url + '" style="height: 45px;">';
164167
}); // Replace [url] with img element
165168

166169
bubble.appendChild(name);
@@ -187,8 +190,7 @@
187190
clearTimeout(pinnedMessageTimeout);
188191
clearInterval(pinnedMessageInterval);
189192
chatContainer.removeEventListener('scroll', pinnedMessageListener);
190-
pinnedMessage.element.style.position = '';
191-
pinnedMessage.element.remove();
193+
pinnedchatContainer.innerHTML = "";
192194
}
193195

194196
// Pin the new message
@@ -214,13 +216,13 @@
214216
chatContainer.addEventListener('scroll', listener);
215217
}
216218

217-
// window.setInterval(function () {
218-
// var pri = Math.random() * 100;
219-
// addPinnedMessage('Name', "表情[img:https://g.csdnimg.cn/static/face/emoji/010.png]测试 优先级" + pri, 'https://i2.hdslb.com/bfs/face/8e80dfc2cc59b1d3d6c48895666aa28b9dd323ae.jpg@150w_150h.jpg', ["Saab"], pri);
220-
// }, 500)
221-
// window.setInterval(function () {
222-
// addMessage('Name', "表情[img:https://g.csdnimg.cn/static/face/emoji/010.png]测试" + Math.random(), 'https://i2.hdslb.com/bfs/face/8e80dfc2cc59b1d3d6c48895666aa28b9dd323ae.jpg@150w_150h.jpg', ["Saab"]);
223-
// }, 300)
219+
//window.setInterval(function () {
220+
// var pri = Math.random() * 100;
221+
// addPinnedMessage('Name', "表情[img:https://g.csdnimg.cn/static/face/emoji/010.png]测试 优先级" + pri, 'https://i2.hdslb.com/bfs/face/8e80dfc2cc59b1d3d6c48895666aa28b9dd323ae.jpg@150w_150h.jpg', ["Saab"], pri);
222+
//}, 500)
223+
//window.setInterval(function () {
224+
// addMessage('Name', "表情[img:https://g.csdnimg.cn/static/face/emoji/010.png]测试" + Math.random(), 'https://i2.hdslb.com/bfs/face/8e80dfc2cc59b1d3d6c48895666aa28b9dd323ae.jpg@150w_150h.jpg', ["Saab"]);
225+
//}, 300)
224226
</script>
225227

226228
<script>
@@ -239,6 +241,24 @@
239241
case 'pinned':
240242
addPinnedMessage(message.name, message.content, message.avatar, message.tags, message.priority);
241243
break;
244+
case 'gift':
245+
addMessage(message.name, "送出 [emoj:" + message.img_url + "]<u>" + message.gift_name + "</u> x" + message.gift_count, message.avatar, message.tags);
246+
break;
247+
case 'crew':
248+
var typename = "未知";
249+
switch (message.ctype) {
250+
case 1:
251+
typename = "总督";
252+
break;
253+
case 2:
254+
typename = "提督";
255+
break;
256+
case 3:
257+
typename = "舰长";
258+
break;
259+
}
260+
addPinnedMessage(message.name, "充值 <u>" + typename + "</u> x" + message.gift_count + "月", message.avatar, message.tags, (4 - message.ctype) * 10);
261+
break;
242262
}
243263
};
244264

0 commit comments

Comments
 (0)