Skip to content

Instantly share code, notes, and snippets.

@koduki
Created December 13, 2022 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koduki/7ce39b38c63b971348774331636680c1 to your computer and use it in GitHub Desktop.
Save koduki/7ce39b38c63b971348774331636680c1 to your computer and use it in GitHub Desktop.
using NicoSitePlugin;
using Plugin;
using SitePlugin;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Text;
namespace VCIConnectPlugin
{
[Export(typeof(IPlugin))]
public class Plugin : IPlugin, IDisposable
{
public string Name { get { return "VCI Connect"; } }
public string Description { get { return "バーチャルキャストのVCIにコメントを連携します"; } }
public IPluginHost Host { get; set; }
public void OnMessageReceived(ISiteMessage message, IMessageMetadata messageMetadata)
{
var msg = parseMesage(message);
var list = new List<string>();
list.Add(" return {");
list.Add("{");
list.Add($"name = \"{msg.name}\",");
list.Add($"comment = \"{msg.comment}\",");
list.Add($"cmntSource = \"{msg.cmntSource}\"");
list.Add("}");
list.Add("}");
var filePath = @"C:\Users\koduki\AppData\LocalLow\infiniteloop Co,Ltd\VirtualCast\EmbeddedScriptWorkspace\commentsender\";
var fileName = "data.lua";
using (var sw = new StreamWriter(filePath + fileName, false, Encoding.UTF8))
{
var contents = string.Join(Environment.NewLine, list);
sw.WriteLine(contents);
}
}
private (string name, string comment, string cmntSource) parseMesage(ISiteMessage message)
{
var name = "(名前なし)";
var comment = "(本文なし)";
var cmntSource = "Unknown";
if (message is INicoMessage NicoMessage)
{
name = "(運営)";
cmntSource = "MCV";
switch (NicoMessage.NicoMessageType)
{
case NicoMessageType.Connected:
comment = (NicoMessage as INicoConnected).Text;
break;
case NicoMessageType.Disconnected:
comment = (NicoMessage as INicoDisconnected).Text;
break;
case NicoMessageType.Item:
comment = (NicoMessage as INicoGift).Text;
break;
case NicoMessageType.Ad:
comment = (NicoMessage as INicoAd).Text;
break;
case NicoMessageType.Spi:
comment = (NicoMessage as INicoSpi).Text;
break;
case NicoMessageType.Info:
comment = (NicoMessage as INicoInfo).Text;
break;
case NicoMessageType.Emotion:
comment = "/emotion " + (NicoMessage as INicoEmotion).Content;
break;
case NicoMessageType.Comment:
if ((NicoMessage as INicoComment).Is184 == true)
{
name = "";
}
else
{
name = (NicoMessage as INicoComment).UserName;
}
comment = (NicoMessage as INicoComment).Text;
cmntSource = "Nicolive";
break;
}
}
return (name, comment, cmntSource);
}
public virtual void OnLoaded()
{
}
public void OnClosing()
{
}
public void OnTopmostChanged(bool isTopmost)
{
}
public void ShowSettingView()
{
}
public void Dispose()
{
Dispose(true);
}
protected virtual void Dispose(bool disposing)
{
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment