Skip to content

Commit

Permalink
Merge pull request #11 from chr233/dev
Browse files Browse the repository at this point in the history
MediaGroup支持增强
  • Loading branch information
chr233 authored May 30, 2023
2 parents f588f59 + e8a8244 commit d306ac7
Show file tree
Hide file tree
Showing 100 changed files with 1,926 additions and 1,218 deletions.
372 changes: 237 additions & 135 deletions .editorconfig

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>2.0.25.1</Version>
<Version>2.1.0.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
10 changes: 5 additions & 5 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageVersion Include="MySql.Data" Version="8.0.32.1" />
<PackageVersion Include="NLog" Version="5.1.3" />
<PackageVersion Include="NLog.Extensions.Logging" Version="5.2.3" />
<PackageVersion Include="MySql.Data" Version="8.0.33" />
<PackageVersion Include="NLog" Version="5.1.5" />
<PackageVersion Include="NLog.Extensions.Logging" Version="5.2.5" />
<PackageVersion Include="Quartz" Version="3.6.2" />
<PackageVersion Include="Quartz.AspNetCore" Version="3.6.2" />
<PackageVersion Include="SqlSugar.IOC" Version="2.0.0" />
<PackageVersion Include="SqlSugarCore" Version="5.1.4.66" />
<PackageVersion Include="SqlSugarCore" Version="5.1.4.80" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageVersion Include="Telegram.Bot" Version="19.0.0-preview.2" />
<PackageVersion Include="Telegram.Bot" Version="19.0.0" />
</ItemGroup>
</Project>
160 changes: 76 additions & 84 deletions XinjingdailyBot.Command/AdminCommand.cs

Large diffs are not rendered by default.

23 changes: 11 additions & 12 deletions XinjingdailyBot.Command/CommonCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Text;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Options;
using System.Text;
using Telegram.Bot;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
Expand Down Expand Up @@ -43,7 +43,7 @@ public CommonCommand(
/// <param name="dbUser"></param>
/// <param name="message"></param>
/// <returns></returns>
[TextCmd("HELP", UserRights.None, Description = "显示命令帮助")]
[TextCmd("HELP", EUserRights.None, Description = "显示命令帮助")]
public async Task ResponseHelp(Users dbUser, Message message)
{
StringBuilder sb = new();
Expand All @@ -68,7 +68,7 @@ public async Task ResponseHelp(Users dbUser, Message message)
/// <param name="dbUser"></param>
/// <param name="message"></param>
/// <returns></returns>
[TextCmd("START", UserRights.None, Description = "首次欢迎语")]
[TextCmd("START", EUserRights.None, Description = "首次欢迎语")]
public async Task ResponseStart(Users dbUser, Message message)
{
StringBuilder sb = new();
Expand Down Expand Up @@ -97,7 +97,7 @@ public async Task ResponseStart(Users dbUser, Message message)
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
[TextCmd("ABOUT", UserRights.None, Description = "关于机器人")]
[TextCmd("ABOUT", EUserRights.None, Description = "关于机器人")]
public async Task ResponseAbout(Message message)
{
StringBuilder sb = new();
Expand All @@ -115,7 +115,7 @@ public async Task ResponseAbout(Message message)
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
[TextCmd("VERSION", UserRights.None, Description = "查看机器人版本")]
[TextCmd("VERSION", EUserRights.None, Description = "查看机器人版本")]
public async Task ResponseVersion(Message message)
{
StringBuilder sb = new();
Expand All @@ -134,7 +134,7 @@ public async Task ResponseVersion(Message message)
/// <param name="dbUser"></param>
/// <param name="message"></param>
/// <returns></returns>
[TextCmd("MYBAN", UserRights.None, Description = "查询自己是否被封禁")]
[TextCmd("MYBAN", EUserRights.None, Description = "查询自己是否被封禁")]
public async Task ResponseMyBan(Users dbUser, Message message)
{
var records = await _banRecordService.Queryable().Where(x => x.UserID == dbUser.UserID)
Expand All @@ -161,11 +161,10 @@ public async Task ResponseMyBan(Users dbUser, Message message)
foreach (var record in records)
{
string date = record.BanTime.ToString("d");
string operate = record.Type switch
{
BanType.UnBan => "解封",
BanType.Ban => "封禁",
BanType.Warning => "警告",
string operate = record.Type switch {
EBanType.UnBan => "解封",
EBanType.Ban => "封禁",
EBanType.Warning => "警告",
_ => "其他",
};
sb.AppendLine($"在 <code>{date}</code> 因为 <code>{record.Reason}</code> 被 {operate}");
Expand Down
57 changes: 27 additions & 30 deletions XinjingdailyBot.Command/NormalCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Net;
using SqlSugar;
using System.Net;
using System.Text;
using SqlSugar;
using Telegram.Bot;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
Expand Down Expand Up @@ -54,7 +54,7 @@ public NormalCommand(
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
[TextCmd("PING", UserRights.NormalCmd, Description = "检测机器人是否存活")]
[TextCmd("PING", EUserRights.NormalCmd, Description = "检测机器人是否存活")]
public async Task ResponsePing(Message message)
{
await _botClient.SendCommandReply("PONG!", message);
Expand All @@ -66,7 +66,7 @@ public async Task ResponsePing(Message message)
/// <param name="dbUser"></param>
/// <param name="message"></param>
/// <returns></returns>
[TextCmd("ANONYMOUS", UserRights.NormalCmd, Alias = "ANYMOUSE", Description = "设置是否匿名")]
[TextCmd("ANONYMOUS", EUserRights.NormalCmd, Alias = "ANYMOUSE", Description = "设置是否匿名")]
public async Task ResponseAnonymous(Users dbUser, Message message)
{
if (message.Chat.Type != ChatType.Private)
Expand All @@ -91,7 +91,7 @@ public async Task ResponseAnonymous(Users dbUser, Message message)
/// <param name="dbUser"></param>
/// <param name="message"></param>
/// <returns></returns>
[TextCmd("NOTIFICATION", UserRights.NormalCmd, Description = "设置稿件审核后是否通知")]
[TextCmd("NOTIFICATION", EUserRights.NormalCmd, Description = "设置稿件审核后是否通知")]
public async Task ResponseNotification(Users dbUser, Message message)
{
if (message.Chat.Type != ChatType.Private)
Expand All @@ -116,7 +116,7 @@ public async Task ResponseNotification(Users dbUser, Message message)
/// <param name="dbUser"></param>
/// <param name="message"></param>
/// <returns></returns>
[TextCmd("MYINFO", UserRights.NormalCmd, Description = "获取自己的信息")]
[TextCmd("MYINFO", EUserRights.NormalCmd, Description = "获取自己的信息")]
public async Task ResponseMyInfo(Users dbUser, Message message)
{
StringBuilder sb = new();
Expand All @@ -138,16 +138,16 @@ public async Task ResponseMyInfo(Users dbUser, Message message)
/// <param name="dbUser"></param>
/// <param name="message"></param>
/// <returns></returns>
[TextCmd("MYRIGHT", UserRights.NormalCmd, Description = "获取自己的权限")]
[TextCmd("MYRIGHT", EUserRights.NormalCmd, Description = "获取自己的权限")]
public async Task ResponseMyRight(Users dbUser, Message message)
{
var right = dbUser.Right;
bool superCmd = right.HasFlag(UserRights.SuperCmd);
bool adminCmd = right.HasFlag(UserRights.AdminCmd);
bool normalCmd = right.HasFlag(UserRights.NormalCmd);
bool sendPost = right.HasFlag(UserRights.SendPost);
bool reviewPost = right.HasFlag(UserRights.ReviewPost);
bool directPost = right.HasFlag(UserRights.DirectPost);
bool superCmd = right.HasFlag(EUserRights.SuperCmd);
bool adminCmd = right.HasFlag(EUserRights.AdminCmd);
bool normalCmd = right.HasFlag(EUserRights.NormalCmd);
bool sendPost = right.HasFlag(EUserRights.SendPost);
bool reviewPost = right.HasFlag(EUserRights.ReviewPost);
bool directPost = right.HasFlag(EUserRights.DirectPost);
string userNick = message.From!.EscapedNickName();

string group = _groupRepository.GetGroupName(dbUser.GroupID);
Expand Down Expand Up @@ -178,7 +178,7 @@ public async Task ResponseMyRight(Users dbUser, Message message)
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
[TextCmd("ADMIN", UserRights.NormalCmd, Description = "艾特群管理")]
[TextCmd("ADMIN", EUserRights.NormalCmd, Description = "艾特群管理")]
public async Task ResponseCallAdmins(Message message)
{
StringBuilder sb = new();
Expand Down Expand Up @@ -210,7 +210,7 @@ public async Task ResponseCallAdmins(Message message)
/// <param name="query"></param>
/// <param name="args"></param>
/// <returns></returns>
[QueryCmd("CANCEL", UserRights.NormalCmd, Alias = "CANCELCLOSE CANCELANDCLOSE")]
[QueryCmd("CANCEL", EUserRights.NormalCmd, Alias = "CANCELCLOSE CANCELANDCLOSE")]
public async Task QResponseCancel(CallbackQuery query, string[] args)
{
string text = args.Length > 1 ? string.Join(' ', args[1..]) : "操作已取消";
Expand All @@ -225,7 +225,7 @@ public async Task QResponseCancel(CallbackQuery query, string[] args)
/// <param name="query"></param>
/// <param name="args"></param>
/// <returns></returns>
[QueryCmd("SAY", UserRights.NormalCmd)]
[QueryCmd("SAY", EUserRights.NormalCmd)]
public async Task QResponseSay(CallbackQuery query, string[] args)
{
string text;
Expand All @@ -246,10 +246,10 @@ public async Task QResponseSay(CallbackQuery query, string[] args)
/// <param name="dbUser"></param>
/// <param name="message"></param>
/// <returns></returns>
[TextCmd("RANDOMPOST", UserRights.NormalCmd, Description = "获取随机稿件")]
[TextCmd("RANDOMPOST", EUserRights.NormalCmd, Description = "获取随机稿件")]
public async Task ResponseRandomPost(Users dbUser, Message message)
{
if (!dbUser.Right.HasFlag(UserRights.AdminCmd))
if (!dbUser.Right.HasFlag(EUserRights.AdminCmd))
{
if (message.Chat.Type != ChatType.Private)
{
Expand All @@ -268,7 +268,7 @@ public async Task ResponseRandomPost(Users dbUser, Message message)
/// <param name="callbackQuery"></param>
/// <param name="args"></param>
/// <returns></returns>
[QueryCmd("SETRANDOMPOST", UserRights.NormalCmd)]
[QueryCmd("SETRANDOMPOST", EUserRights.NormalCmd)]
public async Task QResponseSetRandomPost(Users dbUser, CallbackQuery callbackQuery, string[] args)
{
if (args.Length < 1)
Expand Down Expand Up @@ -301,7 +301,7 @@ public async Task QResponseSetRandomPost(Users dbUser, CallbackQuery callbackQue
/// <param name="callbackQuery"></param>
/// <param name="args"></param>
/// <returns></returns>
[QueryCmd("BACKRANDOMPOST", UserRights.NormalCmd)]
[QueryCmd("BACKRANDOMPOST", EUserRights.NormalCmd)]
public async Task QResponseBackRandomPost(Users dbUser, CallbackQuery callbackQuery)
{
var keyboard = _markupHelperService.RandomPostMenuKeyboard(dbUser);
Expand All @@ -315,7 +315,7 @@ public async Task QResponseBackRandomPost(Users dbUser, CallbackQuery callbackQu
/// <param name="callbackQuery"></param>
/// <param name="args"></param>
/// <returns></returns>
[QueryCmd("RANDOMPOST", UserRights.NormalCmd)]
[QueryCmd("RANDOMPOST", EUserRights.NormalCmd)]
public async Task QGetRandomPost(Users dbUser, CallbackQuery callbackQuery, string[] args)
{
if (args.Length < 3 || !int.TryParse(args[1], out int tagId))
Expand All @@ -324,8 +324,7 @@ public async Task QGetRandomPost(Users dbUser, CallbackQuery callbackQuery, stri
return;
}

MessageType? postType = args[2] switch
{
MessageType? postType = args[2] switch {
"photo" => MessageType.Photo,
"video" => MessageType.Video,
"audio" => MessageType.Audio,
Expand All @@ -338,10 +337,10 @@ public async Task QGetRandomPost(Users dbUser, CallbackQuery callbackQuery, stri
var tag = tagId != 0 ? _tagRepository.GetTagById(tagId) : null;

var randomPost = await _postService.Queryable()
.Where(x => x.Status == PostStatus.Accepted)
.Where(x => x.Status == EPostStatus.Accepted)
.WhereIF(postType == null, x => x.PostType != MessageType.Text)
.WhereIF(postType != null, x => x.PostType == postType)
.WhereIF(tag != null, x => (x.NewTags & tag!.Seg) > 0)
.WhereIF(tag != null, x => (x.Tags & tag!.Seg) > 0)
.OrderBy(x => SqlFunc.GetRandom()).FirstAsync();

if (randomPost != null)
Expand All @@ -361,8 +360,7 @@ public async Task QGetRandomPost(Users dbUser, CallbackQuery callbackQuery, stri
{
attachmentType = randomPost.PostType;
}
group[i] = attachmentType switch
{
group[i] = attachmentType switch {
MessageType.Photo => new InputMediaPhoto(new InputFileId(attachments[i].FileID)) { Caption = i == 0 ? randomPost.Text : null, ParseMode = ParseMode.Html, HasSpoiler = hasSpoiler },
MessageType.Audio => new InputMediaAudio(new InputFileId(attachments[i].FileID)) { Caption = i == 0 ? randomPost.Text : null, ParseMode = ParseMode.Html },
MessageType.Video => new InputMediaVideo(new InputFileId(attachments[i].FileID)) { Caption = i == 0 ? randomPost.Text : null, ParseMode = ParseMode.Html, HasSpoiler = hasSpoiler },
Expand All @@ -381,8 +379,7 @@ public async Task QGetRandomPost(Users dbUser, CallbackQuery callbackQuery, stri
else
{
Attachments attachment = await _attachmentService.Queryable().FirstAsync(x => x.PostID == randomPost.Id);
var handler = randomPost.PostType switch
{
var handler = randomPost.PostType switch {
MessageType.Text => _botClient.SendTextMessageAsync(chat, randomPost.Text),
MessageType.Photo => _botClient.SendPhotoAsync(chat, new InputFileId(attachment.FileID), caption: randomPost.Text, parseMode: ParseMode.Html, replyMarkup: keyboard, hasSpoiler: hasSpoiler),
MessageType.Audio => _botClient.SendAudioAsync(chat, new InputFileId(attachment.FileID), caption: randomPost.Text, parseMode: ParseMode.Html, replyMarkup: keyboard, title: attachment.FileName),
Expand Down Expand Up @@ -420,7 +417,7 @@ public async Task QGetRandomPost(Users dbUser, CallbackQuery callbackQuery, stri
}
}

[TextCmd("IP", UserRights.NormalCmd, Alias = "IPINFO", Description = "查询IP信息")]
[TextCmd("IP", EUserRights.NormalCmd, Alias = "IPINFO", Description = "查询IP信息")]
public async Task GetIpInfo(Message message, string[] args)
{
StringBuilder sb = new();
Expand Down
Loading

0 comments on commit d306ac7

Please sign in to comment.