* 移除了12点大挑战,更新运势至远程服务器

* 完善查看运势

* 更新 API 调用
This commit is contained in:
milimoe 2024-10-17 01:55:08 +08:00 committed by GitHub
parent fb6eebcc22
commit de97084562
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 86 additions and 172 deletions

View File

@ -49,12 +49,6 @@ namespace Milimoe.RainBOT.ListeningTask
return quick_reply;
}
if (e.detail == "挑战结束" && e.user_id == GeneralSettings.Master)
{
await Bot.Unmute12ClockMembers();
return quick_reply;
}
if (e.detail.Length >= 9 && e.detail[..9].Equals("FunGame模拟", StringComparison.CurrentCultureIgnoreCase))
{
if (!await Bot.CheckBlackList(true, e.user_id, e.user_id)) return quick_reply;

View File

@ -5,6 +5,7 @@ using Milimoe.OneBot.Model.Message;
using Milimoe.OneBot.Model.Other;
using Milimoe.OneBot.Model.QuickReply;
using Milimoe.RainBOT.Command;
using Milimoe.RainBOT.Model;
using Milimoe.RainBOT.Settings;
namespace Milimoe.RainBOT.ListeningTask
@ -104,42 +105,6 @@ namespace Milimoe.RainBOT.ListeningTask
return quick_reply;
}
// 12点大挑战
if (e.detail == "加入12点" || e.detail == "加入12点大挑战")
{
if (!await Bot.CheckBlackList(true, e.user_id, e.group_id)) return quick_reply;
if (GeneralSettings.Challenge12ClockGroup.Contains(e.user_id))
{
await Bot.SendGroupMessage(e.group_id, "12点大挑战", "请勿重复加入。");
}
else
{
GeneralSettings.Challenge12ClockGroup.Add(e.user_id);
await Bot.SendGroupMessage(e.group_id, "12点大挑战", "你已成功加入~\r\n发送【退出12点】退出挑战。");
GeneralSettings.SaveConfig();
}
return quick_reply;
}
else if ((e.detail == "退出12点" || e.detail == "退出12点大挑战") && GeneralSettings.Challenge12ClockGroup.Contains(e.user_id))
{
if (!await Bot.CheckBlackList(true, e.user_id, e.group_id)) return quick_reply;
GeneralSettings.Challenge12ClockGroup.Remove(e.user_id);
await Bot.SendGroupMessage(e.group_id, "12点大挑战", "你已成功退出~\r\n发送【加入12点】即可再次参加。");
GeneralSettings.SaveConfig();
return quick_reply;
}
else if (e.detail == "12点大挑战")
{
if (!await Bot.CheckBlackList(true, e.user_id, e.group_id)) return quick_reply;
await Bot.SendGroupMessage(e.group_id, "12点大挑战", "欢迎加入12点大挑战。参加本挑战后你将在每晚的12点获得8小时禁言和优质的睡眠确保第二天的精神饱满\r\n发送【加入12点】即可参加。");
return quick_reply;
}
else if (e.detail == "挑战结束" && e.user_id == GeneralSettings.Master)
{
await Bot.Unmute12ClockMembers();
return quick_reply;
}
if (e.detail.Length >= 9 && e.detail[..9].Equals("FunGame模拟", StringComparison.CurrentCultureIgnoreCase))
{
if (!await Bot.CheckBlackList(true, e.user_id, e.group_id)) return quick_reply;
@ -280,63 +245,57 @@ namespace Milimoe.RainBOT.ListeningTask
if (e.detail == "我的运势")
{
if (!await Bot.CheckBlackList(true, e.user_id, e.group_id)) return quick_reply;
GroupMessageContent content = new(e.group_id);
content.message.Add(new AtMessage(e.user_id));
if (Daily.UserDailys.TryGetValue(e.user_id, out string? value) && value != null && value.Trim() != "")
UserDaily daily = await Bot.HttpPost<UserDaily>("https://api.milimoe.com/userdaily/get/" + e.user_id, "") ?? new(0, 0, "");
if (daily.daily != "")
{
content.message.Add(new TextMessage("你已看过你的今日运势:\r\n"));
content.message.Add(new TextMessage(value));
await Bot.SendGroupMessage(e.group_id, "我的运势", content);
}
else
{
int seq = new Random().Next(Daily.DailyContent.Count);
string text = Daily.DailyContent[seq];
Daily.UserDailys.Add(e.user_id, text);
content.message.Add(new TextMessage("你的今日运势是:\r\n" + text));
await Bot.SendGroupMessage(e.group_id, "我的运势", content);
// 配图
content = new(e.group_id);
string img = "file:///" + AppDomain.CurrentDomain.BaseDirectory.ToString() + @"img\zi\";
if (seq >= 0 && seq <= 5)
{
img += "dj" + (new Random().Next(3) + 1) + ".png";
}
else if (seq >= 6 && seq <= 10)
{
img += "zj" + (new Random().Next(2) + 1) + ".png";
}
else if (seq >= 11 && seq <= 15)
{
img += "j" + (new Random().Next(4) + 1) + ".png";
}
else if (seq >= 16 && seq <= 22)
{
img += "mj" + (new Random().Next(2) + 1) + ".png";
}
else if (seq >= 23 && seq <= 25)
{
img += "dx" + (new Random().Next(2) + 1) + ".png";
}
else if (seq >= 26 && seq <= 29)
{
img += "x" + (new Random().Next(2) + 1) + ".png";
}
content.message.Add(new ImageMessage(img));
await Bot.SendGroupMessage(e.group_id, "我的运势配图", content);
Daily.SaveDaily();
if (daily.type == 0)
{
GroupMessageContent content = new(e.group_id);
content.message.Add(new AtMessage(e.user_id));
content.message.Add(new TextMessage(daily.daily));
await Bot.SendGroupMessage(e.group_id, "我的运势", content);
}
else
{
string img = "file:///" + AppDomain.CurrentDomain.BaseDirectory.ToString() + @"img\zi\";
img += daily.type switch
{
1 => "dj" + (new Random().Next(3) + 1) + ".png",
2 => "zj" + (new Random().Next(2) + 1) + ".png",
3 => "j" + (new Random().Next(4) + 1) + ".png",
4 => "mj" + (new Random().Next(2) + 1) + ".png",
5 => "x" + (new Random().Next(2) + 1) + ".png",
6 => "dx" + (new Random().Next(2) + 1) + ".png",
_ => ""
};
GroupMessageContent content = new(e.group_id);
content.message.Add(new AtMessage(e.user_id));
content.message.Add(new TextMessage(daily.daily));
await Bot.SendGroupMessage(e.group_id, "我的运势", content);
content = new(e.group_id);
content.message.Add(new ImageMessage(img));
await Bot.SendGroupMessage(e.group_id, "我的运势配图", content);
}
}
return quick_reply;
}
if (e.detail == "重置运势" && Daily.UserDailys.ContainsKey(e.user_id))
if (e.detail == "重置运势")
{
if (!await Bot.CheckBlackList(true, e.user_id, e.group_id)) return quick_reply;
Daily.UserDailys.Remove(e.user_id);
GroupMessageContent content = new(e.group_id);
content.message.Add(new AtMessage(e.user_id));
content.message.Add(new TextMessage("你的今日运势已重置。"));
await Bot.SendGroupMessage(e.group_id, "重置运势", content);
Daily.SaveDaily();
string msg = await Bot.HttpPost<string>("https://api.milimoe.com/userdaily/remove/" + e.user_id, "") ?? "";
if (msg != "")
{
GroupMessageContent content = new(e.group_id);
content.message.Add(new AtMessage(e.user_id));
content.message.Add(new TextMessage(msg));
await Bot.SendGroupMessage(e.group_id, "重置运势", content);
}
return quick_reply;
}
if (e.detail.Length > 4 && e.detail[..2] == "查看" && (e.detail[^2..] == "运势"))
@ -347,22 +306,18 @@ namespace Milimoe.RainBOT.ListeningTask
{
if (long.TryParse(str_qq.Trim().Replace("@", ""), out long qq))
{
if (qq == GeneralSettings.BotQQ && !Daily.UserDailys.ContainsKey(qq))
if (qq == GeneralSettings.BotQQ)
{
string text = Daily.DailyContent[new Random().Next(Daily.DailyContent.Count)];
Daily.UserDailys.Add(GeneralSettings.BotQQ, text);
Daily.SaveDaily();
await Bot.HttpPost<UserDaily>("https://api.milimoe.com/userdaily/get/" + qq, "");
}
if (Daily.UserDailys.TryGetValue(qq, out string? daily) && daily != null)
UserDaily daily = await Bot.HttpGet<UserDaily>("https://api.milimoe.com/userdaily/view/" + qq) ?? new(0, 0, "");
if (daily.daily != "")
{
GroupMessageContent content = new(e.group_id);
content.message.Add(new TextMessage(Bot.GetMemberNickName(e.group_id, qq) + "" + qq + ")的今日运势是:\r\n" + daily));
content.message.Add(new AtMessage(e.user_id));
content.message.Add(new TextMessage(daily.daily));
await Bot.SendGroupMessage(e.group_id, "查看运势", content);
}
else
{
await Bot.SendGroupMessage(e.group_id, "查看运势", "TA今天还没有抽取运势哦快去提醒TA");
}
}
}
return quick_reply;
@ -375,9 +330,11 @@ namespace Milimoe.RainBOT.ListeningTask
{
if (long.TryParse(str_qq.Trim().Replace("@", ""), out long qq))
{
Daily.UserDailys.Remove(GeneralSettings.BotQQ);
await Bot.SendGroupMessage(e.group_id, "重置运势", "已重置" + Bot.GetMemberNickName(e.group_id, qq) + "" + qq + ")的今日运势。");
Daily.SaveDaily();
string msg = await Bot.HttpPost<string>("https://api.milimoe.com/userdaily/remove/" + e.user_id, "") ?? "";
if (msg != "")
{
await Bot.SendGroupMessage(e.group_id, "重置运势", "已重置" + Bot.GetMemberNickName(e.group_id, qq) + "" + qq + ")的今日运势。");
}
}
}
return quick_reply;

View File

@ -156,7 +156,7 @@ try
Console.WriteLine("已重置所有人的今日运势。");
Console.ForegroundColor = ConsoleColor.Gray;
// 发放12点大挑战的奖励
await Bot.Send12ClockPresents();
//await Bot.Send12ClockPresents();
}
if (now.Hour == 0 && now.Minute == 1)
{

11
src/Model/UserDaily.cs Normal file
View File

@ -0,0 +1,11 @@
namespace Milimoe.RainBOT.Model
{
public class UserDaily(long user_id, long type, string daily)
{
#pragma warning disable IDE1006 // 命名样式
public long user_id { get; set; } = user_id;
public long type { get; set; } = type;
public string daily { get; set; } = daily;
#pragma warning restore IDE1006 // 命名样式
}
}

View File

@ -331,57 +331,6 @@ namespace Milimoe.RainBOT.Settings
else await SendGroupMessage(group_id, "OSM指令", "你没有权限使用此指令。");
}
public static async Task Send12ClockPresents()
{
foreach (long group_id in GroupMembers.Keys)
{
List<IContent> list = [];
foreach (Member m in GroupMembers[group_id])
{
if (GeneralSettings.Challenge12ClockGroup.Contains(m.user_id))
{
SetGroupBanContent content = new(group_id, m.user_id, 28800);
list.Add(content);
await Task.Delay(3000);
if (MuteRecall.Muted[group_id].ContainsKey(m.user_id)) MuteRecall.Muted[group_id][m.user_id] = GeneralSettings.BotQQ;
else MuteRecall.Muted[group_id].Add(m.user_id, GeneralSettings.BotQQ);
}
}
if (list.Count > 0)
{
await SendMessage(SupportedAPI.set_group_ban, group_id, "12点大挑战", list, true);
await SendGroupMessage(group_id, "12点大挑战", "12点大挑战的奖励现已发放\r\n添加Bot为好友即可享受私聊【忏悔】解除禁言的特权。\r\n发送【退出12点】即可退出挑战");
}
}
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("已向12点大挑战的成员发放奖励。");
Console.ForegroundColor = ConsoleColor.Gray;
}
public static async Task Unmute12ClockMembers()
{
foreach (long group_id in GroupMembers.Keys)
{
List<IContent> list = [];
foreach (Member m in GroupMembers[group_id])
{
if (GeneralSettings.Challenge12ClockGroup.Contains(m.user_id))
{
MuteRecall.Muted.Remove(m.user_id);
SetGroupBanContent content = new(group_id, m.user_id, 0);
list.Add(content);
}
}
if (list.Count > 0)
{
await SendMessage(SupportedAPI.set_group_ban, group_id, "12点大挑战", list, true);
}
}
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("已解禁所有参与12点大挑战的成员。");
Console.ForegroundColor = ConsoleColor.Gray;
}
private static readonly HttpClient client = new();
public static async Task<T?> HttpGet<T>(string url)

View File

@ -54,8 +54,6 @@ namespace Milimoe.RainBOT.Settings
public static List<long> OSMCoreGroup { get; set; } = [];
public static List<long> Challenge12ClockGroup { get; set; } = [];
public static PluginConfig Configs { get; set; } = new("rainbot", "config");
public static void LoadSetting()
@ -154,10 +152,6 @@ namespace Milimoe.RainBOT.Settings
{
OSMCoreGroup = (List<long>)value;
}
if (configs.TryGetValue("Challenge12ClockGroup", out value) && value != null)
{
Challenge12ClockGroup = (List<long>)value;
}
}
public static void SaveConfig()
@ -184,7 +178,6 @@ namespace Milimoe.RainBOT.Settings
Configs.Add("RecallAccessGroup", RecallAccessGroup);
Configs.Add("SayNoAccessGroup", SayNoAccessGroup);
Configs.Add("OSMCoreGroup", OSMCoreGroup);
Configs.Add("Challenge12ClockGroup", Challenge12ClockGroup);
Configs.Save();
}
@ -208,9 +201,6 @@ namespace Milimoe.RainBOT.Settings
case "osmcoregroup":
list = OSMCoreGroup;
break;
case "challenge12clockgroup":
list = Challenge12ClockGroup;
break;
}
string msg = list.Count > 0 ? "权限组" + group + "拥有以下成员:" + "\r\n" + string.Join("\r\n", list) : "此权限组不存在或没有任何成员。";
_ = isgroup ? Bot.SendGroupMessage(target, "显示列表成员", msg) : Bot.SendFriendMessage(target, "显示列表成员", msg);

View File

@ -1,11 +1,24 @@
namespace Milimoe.RainBOT.Settings
using System.Globalization;
using System.Reflection;
namespace Milimoe.RainBOT.Settings
{
public class OSMCore
{
public const string version = "v1.0";
public const string version2 = "Patch10";
public const string time = "Sep. 22nd 2024";
public const string version2 = "Patch11 Test1";
public static string Info => $"OSM Core {version} {version2}\r\nAuthor: Milimoe\r\nBuilt on {time}\r\nSee: https://github.com/milimoe";
public static string Info => $"OSM Core {version} {version2}\r\nAuthor: Milimoe\r\nBuilt on {GetBuiltTime(Assembly.GetExecutingAssembly().Location)}\r\nSee: https://github.com/milimoe";
public static string GetBuiltTime(string dll_name)
{
DateTime lastWriteTime = File.GetLastWriteTime(dll_name);
string month = lastWriteTime.ToString("MMM", CultureInfo.InvariantCulture);
int day = lastWriteTime.Day;
string time = lastWriteTime.ToString("HH:mm:ss", CultureInfo.InvariantCulture);
return $"{month}. {day}, {lastWriteTime.Year} {time}";
}
}
}