Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed Aug 17, 2023
1 parent 2168e14 commit ce7050e
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 17 deletions.
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.1.5.4</Version>
<Version>2.1.6.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
9 changes: 8 additions & 1 deletion XinjingdailyBot.Command/SuperCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,17 @@ async Task<string> exec()
[TextCmd("COMMAND", EUserRights.SuperCmd, Description = "设置命令菜单")]
public async Task ResponseCommand(Message message)
{
bool result = await _commandHandler.GetCommandsMenu();
bool result = await _commandHandler.SetCommandsMenu();
await _botClient.SendCommandReply(result ? "设置菜单成功" : "设置菜单失败", message, autoDelete: false);
}

[TextCmd("CLEARCOMMAND", EUserRights.SuperCmd, Description = "设置命令菜单")]
public async Task ResponseClearCommand(Message message)
{
bool result = await _commandHandler.ClearCommandsMenu();
await _botClient.SendCommandReply(result ? "清除菜单成功" : "清除菜单失败", message, autoDelete: false);
}

/// <summary>
/// 重新计算用户投稿数量
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion XinjingdailyBot.Interface/Bot/Handler/ICommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface ICommandHandler
/// 设置菜命令单
/// </summary>
/// <returns></returns>
Task<bool> GetCommandsMenu();
Task<bool> SetCommandsMenu();
/// <summary>
/// 注册命令
/// </summary>
Expand All @@ -39,4 +39,5 @@ public interface ICommandHandler
/// <param name="query"></param>
/// <returns></returns>
Task OnQueryCommandReceived(Users dbUser, CallbackQuery query);
Task<bool> ClearCommandsMenu();
}
15 changes: 14 additions & 1 deletion XinjingdailyBot.Service/Bot/Handler/CommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ public string GetAvilabeCommands(Users dbUser)
}
}

public async Task<bool> GetCommandsMenu()
public async Task<bool> SetCommandsMenu()
{
var cmds = new List<BotCommand>();

Expand All @@ -474,6 +474,7 @@ void AddCommands(EUserRights right)

AddCommands(EUserRights.None);
AddCommands(EUserRights.NormalCmd);
await _botClient.SetMyCommandsAsync(cmds, null);
await _botClient.SetMyCommandsAsync(cmds, new BotCommandScopeAllPrivateChats());
await _botClient.SetMyCommandsAsync(cmds, new BotCommandScopeAllGroupChats());

Expand All @@ -484,4 +485,16 @@ void AddCommands(EUserRights right)
await _botClient.SetMyCommandsAsync(cmds, new BotCommandScopeChatAdministrators { ChatId = _channelService.ReviewGroup.Id });
return true;
}

public async Task<bool> ClearCommandsMenu()
{
var cmds = new List<BotCommand>();

await _botClient.SetMyCommandsAsync(cmds);
await _botClient.SetMyCommandsAsync(cmds, new BotCommandScopeAllPrivateChats());
await _botClient.SetMyCommandsAsync(cmds, new BotCommandScopeAllGroupChats());
await _botClient.SetMyCommandsAsync(cmds, new BotCommandScopeAllChatAdministrators());
await _botClient.SetMyCommandsAsync(cmds, new BotCommandScopeChatAdministrators { ChatId = _channelService.ReviewGroup.Id });
return true;
}
}
72 changes: 59 additions & 13 deletions XinjingdailyBot.Service/Data/PostService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,21 +527,29 @@ public async Task SetPostTag(NewPosts post, string payload, CallbackQuery callba

public async Task RejetPost(NewPosts post, Users dbUser, RejectReasons rejectReason)
{
post.RejectReason = rejectReason.Name;
post.CountReject = rejectReason.IsCount;
post.ReviewerUID = dbUser.UserID;
post.Status = EPostStatus.Rejected;
post.ModifyAt = DateTime.Now;
await Updateable(post).UpdateColumns(static x => new {
x.RejectReason,
x.CountReject,
x.ReviewerUID,
x.Status,
x.ModifyAt
}).ExecuteCommandAsync();

var poster = await _userService.Queryable().FirstAsync(x => x.UserID == post.PosterUID);

if (poster.IsBan)
{
await RejectIfBan(post, poster, dbUser, null);
return;
}
else
{
post.RejectReason = rejectReason.Name;
post.CountReject = rejectReason.IsCount;
post.ReviewerUID = dbUser.UserID;
post.Status = EPostStatus.Rejected;
post.ModifyAt = DateTime.Now;
await Updateable(post).UpdateColumns(static x => new {
x.RejectReason,
x.CountReject,
x.ReviewerUID,
x.Status,
x.ModifyAt
}).ExecuteCommandAsync();
}

//修改审核群消息
string reviewMsg = _textHelperService.MakeReviewMessage(poster, dbUser, post.Anonymous, rejectReason.FullText);
await _botClient.EditMessageTextAsync(post.ReviewActionChatID, (int)post.ReviewActionMsgID, reviewMsg, parseMode: ParseMode.Html, disableWebPagePreview: true);
Expand Down Expand Up @@ -634,10 +642,48 @@ public async Task RejetPost(NewPosts post, Users dbUser, RejectReasons rejectRea
}
}

/// <summary>
/// 拒绝封禁用户的投稿
/// </summary>
/// <param name="post"></param>
/// <param name="poster"></param>
/// <param name="reviewer"></param>
/// <param name="callbackQuery"></param>
/// <returns></returns>
private async Task RejectIfBan(NewPosts post, Users poster, Users reviewer, CallbackQuery? callbackQuery)
{
post.RejectReason = "封禁自动拒绝";
post.CountReject = true;
post.ReviewerUID = reviewer.UserID;
post.Status = EPostStatus.Rejected;
post.ModifyAt = DateTime.Now;
await Updateable(post).UpdateColumns(static x => new {
x.RejectReason,
x.CountReject,
x.ReviewerUID,
x.Status,
x.ModifyAt
}).ExecuteCommandAsync();

if (callbackQuery != null)
{
await _botClient.AutoReplyAsync("此用户已被封禁,无法通过审核", callbackQuery);

string reviewMsg = _textHelperService.MakeReviewMessage(poster, reviewer, post.Anonymous, "此用户已被封禁");
await _botClient.EditMessageTextAsync(callbackQuery.Message!, reviewMsg, parseMode: ParseMode.Html, disableWebPagePreview: true);
}
}

public async Task AcceptPost(NewPosts post, Users dbUser, bool inPlan, CallbackQuery callbackQuery)
{
var poster = await _userService.Queryable().FirstAsync(x => x.UserID == post.PosterUID);

if (poster.IsBan)
{
await RejectIfBan(post, poster, dbUser, callbackQuery);
return;
}

ChannelOptions? channel = null;
if (post.IsFromChannel)
{
Expand Down

0 comments on commit ce7050e

Please sign in to comment.