Skip to content

Commit

Permalink
Add Plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Controllerdestiny committed Dec 19, 2024
1 parent fb69351 commit 9993c7a
Show file tree
Hide file tree
Showing 27 changed files with 735 additions and 44 deletions.
8 changes: 2 additions & 6 deletions Bilibili/Bilibili.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Bilibili;

public partial class Bilibili : XocMatPlugin
public partial class Bilibili(ILogger logger, CommandManager commandManager, BotContext bot) : XocMatPlugin(logger, commandManager, bot)
{
public override string Name => "Bilibili插件";

Expand All @@ -24,10 +24,6 @@ public partial class Bilibili : XocMatPlugin

private HttpClient _httpClient = null!;

public Bilibili(ILogger logger, CommandManager commandManager, BotContext bot) : base(logger, commandManager, bot)
{
}

private async Task<MessageBuilder> ParseVideo(string parseUrl, string id, MessageBuilder builder)
{
try
Expand Down Expand Up @@ -153,7 +149,7 @@ private void Event_OnGroupMessage(BotContext bot, GroupMessageEvent args)
{
var _b23 = b23.Groups["B23"].Value;
var url = $"https://{_b23}";
var response = _httpClient.GetAsync(url).Result;
var response = _httpClient.GetAsync(url).Result;
response.EnsureSuccessStatusCode();
var path = response.RequestMessage?.RequestUri?.OriginalString ?? throw new Exception("request uri is null.");
var bvid = BilibiliHelpers.BVIDRegex().Match(path).Groups["BVID"].Value;
Expand Down
3 changes: 3 additions & 0 deletions BindTSplayer/BindTSplayer.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\template.targets" />
</Project>
111 changes: 111 additions & 0 deletions BindTSplayer/Plugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@


using Lagrange.Core;
using Lagrange.XocMat.Commands;
using Lagrange.XocMat.Configuration;
using Lagrange.XocMat.DB.Manager;
using Lagrange.XocMat.Extensions;
using Lagrange.XocMat.Plugin;
using Lagrange.XocMat.Utility;
using Microsoft.Extensions.Logging;

namespace BindTSplayer;

public class Plugin(ILogger logger, CommandManager commandManager, BotContext bot) : XocMatPlugin(logger, commandManager, bot)
{
public override string Name => "BindTSPlayer";

public override string Description => "提供除注册以外的绑定账号功能";

public override string Author => "少司命";

public override Version Version => new(1, 0, 0, 0);


private readonly Dictionary<long, List<Tuple<string, string>>> _temp = [];

public override void Initialize()
{
CommandManager.AddGroupCommand(new("绑定", BindPlayer, "onebot.tshock.bind"));
}

private async ValueTask BindPlayer(CommandArgs args)
{
if (!UserLocation.Instance.TryGetServer(args.EventArgs.Chain.GroupMemberInfo!.Uin, args.EventArgs.Chain.GroupUin!.Value, out var server) || server == null)
{
await args.EventArgs.Reply("服务器不存在或,未切换至一个服务器!", true);
return;
}
if (TerrariaUser.GetUserById(args.EventArgs.Chain.GroupMemberInfo!.Uin, server.Name).Count >= server.RegisterMaxCount)
{
await args.EventArgs.Reply($"同一个服务器上绑定账户不能超过{server.RegisterMaxCount}个", true);
return;
}

if (args.Parameters.Count == 1)
{
var userName = args.Parameters[0];
var account = await server.QueryAccount();
if (!account.Status || !account.Accounts.Any(x => x.Name == userName))
{
await args.EventArgs.Reply($"没有在服务器中找到{userName}账户,无法绑定!", true);
return;
}
var token = Guid.NewGuid().ToString()[..8];
AddTempData(args.EventArgs.Chain.GroupUin!.Value, userName, token);
MailHelper.SendMail($"{args.EventArgs.Chain.GroupMemberInfo!.Uin}@qq.com", "绑定账号验证码", $"您的验证码为: {token}");
await args.EventArgs.Reply($"绑定账号 {userName} => {args.EventArgs.Chain.GroupMemberInfo.Uin}{server.Name}服务器!" +
$"\n请在之后进行使用/绑定 验证 [令牌]" +
$"\n验证令牌已发送至你的邮箱点击下方链接可查看" +
$"\nhttps://wap.mail.qq.com/home/index");
}
else if (args.Parameters.Count == 2 && args.Parameters[0] == "验证")
{
if (GetTempData(args.EventArgs.Chain.GroupUin!.Value, args.Parameters[1], out var name) && !string.IsNullOrEmpty(name))
{
try
{
TerrariaUser.Add(args.EventArgs.Chain.GroupMemberInfo.Uin, args.EventArgs.Chain.GroupUin!.Value, server.Name, name, "");
await args.EventArgs.Reply($"验证完成!\n已绑定账号至{server.Name}服务器!", true);
}
catch (Exception ex)
{
await args.EventArgs.Reply(ex.Message, true);
}
}
else
{
await args.EventArgs.Reply($"请先输入{args.CommamdPrefix}{args.Name} [名称] 在进行验证", true);
}
}
}

public void AddTempData(long groupid, string name, string token)
{
if (_temp.TryGetValue(groupid, out var list) && list != null)
{
list.Add(new Tuple<string, string>(name, token));
}
else
{
_temp[groupid] = [new Tuple<string, string>(name, token)];
}
}

public bool GetTempData(long groupid, string token, out string? name)
{
if (_temp.TryGetValue(groupid, out var list) && list != null)
{
var res = list.Find(x => x.Item2 == token);
name = res?.Item1;
return res != null;
}
name = null;
return false;
}

protected override void Dispose(bool dispose)
{
CommandManager.GroupCommandDelegate.RemoveAll(x => x.CallBack == BindPlayer);
}
}
8 changes: 8 additions & 0 deletions BindTSplayer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# BindPlayer 绑定玩家TS账号
- 注册之外的手段

## 指令
| 名称 | 说明 | 权限 |
|----------|:------------------:|:------------------:|
| /绑定 | 绑定账号 ||

14 changes: 5 additions & 9 deletions Disorder/Disorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Disorder;

public class Disorder : XocMatPlugin
public class Disorder(ILogger logger, CommandManager commandManager, BotContext bot) : XocMatPlugin(logger, commandManager, bot)
{
private const string FellowUrl = "https://oiapi.net/API/CPUni/";

Expand All @@ -20,10 +20,6 @@ public class Disorder : XocMatPlugin

private readonly static HttpClient client = new();

public Disorder(ILogger logger, CommandManager commandManager, BotContext bot) : base(logger, commandManager, bot)
{
}

public override void Initialize()
{
CommandManager.AddGroupCommand(new("今日道侣", Fellow, ""));
Expand All @@ -42,7 +38,7 @@ private async ValueTask Cos(CommandArgs args)
foreach (var img in arr)
{
var url = img?.ToString();
if(url == null) continue;
if (url == null) continue;
chains.Add(MessageBuilder.Friend(args.EventArgs.Chain.GroupMemberInfo!.Uin).Image(HttpUtils.HttpGetByte(url).Result).Build());
}
var build = MessageBuilder.Group(args.EventArgs.Chain.GroupUin!.Value);
Expand Down Expand Up @@ -84,17 +80,17 @@ private async ValueTask Fellow(CommandArgs args)

}
else
{
{
var members = await args.Bot.FetchMembers(args.EventArgs.Chain.GroupUin!.Value);
var targer = members.OrderBy(x => Guid.NewGuid()).First();
targerid = targer.Uin;
targetName = targer.MemberName.Length > 6 ? targer.MemberName[..6] : targer.MemberName;
FollowConfig.Instance.SaveFollow(args.EventArgs.Chain.GroupMemberInfo!.Uin, targerid, targetName);
FollowConfig.Save();
}

var stream = await client.GetByteArrayAsync(FellowUrl + $"?first={(args.EventArgs.Chain.GroupMemberInfo!.MemberName.Length > 6 ? args.EventArgs.Chain.GroupMemberInfo!.MemberName[..6] : args.EventArgs.Chain.GroupMemberInfo!.MemberCard)}&second={targetName}");
List<MessageChain> chains =[
List<MessageChain> chains = [
MessageBuilder.Friend(args.EventArgs.Chain.GroupMemberInfo!.Uin).Text($"今日道侣").Build(),
MessageBuilder.Friend(args.EventArgs.Chain.GroupMemberInfo!.Uin).Image(HttpUtils.HttpGetByte($"http://q.qlogo.cn/headimg_dl?dst_uin={targerid}&spec=640&img_type=png").Result).Text($"账号: {targerid}\n昵称: {targetName}").Build(),
MessageBuilder.Friend(args.EventArgs.Chain.GroupMemberInfo!.Uin).Image(stream).Build()
Expand Down
5 changes: 2 additions & 3 deletions Disorder/FollowConfig.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Lagrange.XocMat.Attributes;
using Lagrange.XocMat.Configuration;
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace Disorder;

Expand All @@ -11,13 +10,13 @@ public class FollowConfig : JsonConfigBase<FollowConfig>
public class FollowWeapon
{
[JsonProperty("时间")]
public DateTime Time { get; set;}
public DateTime Time { get; set; }

[JsonProperty("道侣")]
public long Follow { get; set; }

[JsonProperty("名称")]
public string WeaponName { get; set;} = string.Empty;
public string WeaponName { get; set; } = string.Empty;
}

protected override string Filename => "Follow";
Expand Down
1 change: 0 additions & 1 deletion Disorder/JrrpConfig.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Lagrange.XocMat.Attributes;
using Lagrange.XocMat.Configuration;
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace Disorder;

Expand Down
1 change: 0 additions & 1 deletion Music/Config.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Lagrange.XocMat.Attributes;
using Lagrange.XocMat.Configuration;
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace Music;

Expand Down
16 changes: 4 additions & 12 deletions Music/Music.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,17 @@

using Lagrange.Core;
using Lagrange.Core.Message;
using Lagrange.XocMat;
using Lagrange.XocMat.Commands;
using Lagrange.XocMat.EventArgs;
using Lagrange.XocMat.Extensions;
using Lagrange.XocMat.Permission;
using Lagrange.XocMat.Plugin;
using Lagrange.XocMat.Utility;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System.Security.Cryptography;

namespace Music;

public class Music : XocMatPlugin
public class Music(ILogger logger, CommandManager commandManager, BotContext bot) : XocMatPlugin(logger, commandManager, bot)
{
public Music(ILogger logger, CommandManager commandManager, BotContext bot) : base(logger, commandManager, bot)
{
}

public override string Name => "Music";

public override string Description => "提供点歌功能";
Expand All @@ -30,7 +22,7 @@ public Music(ILogger logger, CommandManager commandManager, BotContext bot) : ba
public override Version Version => new(1, 0, 0, 0);

public override void Initialize()
{
{
CommandManager.AddGroupCommand(new("点歌", MusicCmd, OneBotPermissions.Music));
CommandManager.AddGroupCommand(new("选", ChageMusic, OneBotPermissions.Music));
}
Expand Down Expand Up @@ -129,7 +121,7 @@ private async ValueTask ChageMusic(CommandArgs args)
var music = await MusicTool.GetMusicQQ(musicName, id);
var json = MusicSigner.Sign(new("qq", music!.Url, music.Music, music.Picture, music.Song, music.Singer));
if (json != null)
await args.EventArgs.Reply( MessageBuilder.Group(args.EventArgs.Chain.GroupUin!.Value).LightApp(json));
await args.EventArgs.Reply(MessageBuilder.Group(args.EventArgs.Chain.GroupUin!.Value).LightApp(json));
}
catch (Exception ex)
{
Expand All @@ -146,7 +138,7 @@ private async ValueTask ChageMusic(CommandArgs args)
var json = MusicSigner.Sign(new("163", music!.JumpUrl, music.MusicUrl, music.Picture, music.Name, string.Join(",", music.Singers)));
if (json != null)
await args.EventArgs.Reply(MessageBuilder.Group(args.EventArgs.Chain.GroupUin!.Value).LightApp(json));

}
catch (Exception ex)
{
Expand Down
2 changes: 1 addition & 1 deletion Music/QQ/ApiRespone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ public class ApiRespone
///
/// </summary>
[JsonProperty("data")]
public JObject? Data { get; set; }
public JToken? Data { get; set; }
}
1 change: 0 additions & 1 deletion Music/QQ/MusicData.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@


using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace Music.QQ;

Expand Down
1 change: 0 additions & 1 deletion Music/QQ/MusicItem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace Music.QQ;

Expand Down
26 changes: 26 additions & 0 deletions OnlineReward/Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Newtonsoft.Json;
using Lagrange.XocMat.Attributes;
using Lagrange.XocMat.Configuration;

namespace OnlineReward;

[ConfigSeries]
public class Config : JsonConfigBase<Config>
{
protected override string Filename => "OnlineReward";

protected override string? ReloadMsg => "[OnlineReward] config reload successfully!\n";

[JsonProperty("领取比例")]
public int TimeRate { get; set; } = 100;

[JsonProperty("领取记录")]
public Dictionary<string, int> Reward { get; set; } = [];

public void Reset()
{
Reward.Clear();
Save();
}

}
3 changes: 3 additions & 0 deletions OnlineReward/OnlineReward.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\template.targets" />
</Project>
Loading

0 comments on commit 9993c7a

Please sign in to comment.