Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed Jun 9, 2023
1 parent 0e8c60e commit e8e3ed5
Show file tree
Hide file tree
Showing 18 changed files with 537 additions and 169 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.2.0</Version>
<Version>2.1.2.1</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion XinjingdailyBot.Command/NormalCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ public async Task QGetRandomPost(Users dbUser, CallbackQuery callbackQuery, stri
MessageType.Video => _botClient.SendVideoAsync(chat, new InputFileId(attachment.FileID), caption: randomPost.Text, parseMode: ParseMode.Html, replyMarkup: keyboard, hasSpoiler: hasSpoiler),
MessageType.Voice => _botClient.SendVoiceAsync(chat, new InputFileId(attachment.FileID), caption: randomPost.Text, parseMode: ParseMode.Html, replyMarkup: keyboard),
MessageType.Document => _botClient.SendDocumentAsync(chat, new InputFileId(attachment.FileID), caption: randomPost.Text, parseMode: ParseMode.Html, replyMarkup: keyboard),
MessageType.Animation => _botClient.SendDocumentAsync(chat, new InputFileId(attachment.FileID), caption: randomPost.Text, parseMode: ParseMode.Html, replyMarkup: keyboard),
MessageType.Animation => _botClient.SendAnimationAsync(chat, new InputFileId(attachment.FileID), caption: randomPost.Text, parseMode: ParseMode.Html, replyMarkup: keyboard),
_ => null,
};

Expand Down
6 changes: 3 additions & 3 deletions XinjingdailyBot.Command/PostCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ private async Task ConfirmPost(NewPosts post, Users dbUser, CallbackQuery query)
Caption = i == attachments.Count - 1 ? post.Text : null,
ParseMode = ParseMode.Html
},
_ => throw new Exception(),
_ => throw new Exception("未知的稿件类型"),
};
}
var messages = await _botClient.SendMediaGroupAsync(_channelService.ReviewGroup.Id, group);
var messages = await _botClient.SendMediaGroupAsync(_channelService.ReviewGroup, group);
reviewMsg = messages.First();
post.ReviewMediaGroupID = reviewMsg.MediaGroupId ?? "";

Expand All @@ -196,7 +196,7 @@ private async Task ConfirmPost(NewPosts post, Users dbUser, CallbackQuery query)
bool? hasSpoiler = post.CanSpoiler ? post.HasSpoiler : null;
var keyboard = _markupHelperService.ReviewKeyboardA(post.Tags, hasSpoiler);

var manageMsg = await _botClient.SendTextMessageAsync(_channelService.ReviewGroup.Id, msg, parseMode: ParseMode.Html, disableWebPagePreview: true, replyToMessageId: reviewMsg.MessageId, replyMarkup: keyboard, allowSendingWithoutReply: true);
var manageMsg = await _botClient.SendTextMessageAsync(_channelService.ReviewGroup, msg, parseMode: ParseMode.Html, disableWebPagePreview: true, replyToMessageId: reviewMsg.MessageId, replyMarkup: keyboard, allowSendingWithoutReply: true);

post.ReviewChatID = reviewMsg.Chat.Id;
post.ReviewMsgID = reviewMsg.MessageId;
Expand Down
8 changes: 4 additions & 4 deletions XinjingdailyBot.Infrastructure/Localization/Langs.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions XinjingdailyBot.Infrastructure/Localization/Langs.resx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
<value>#AI怪图</value>
</data>
<data name="TagSpoilerOn" xml:space="preserve">
<value>⚠️开启遮罩</value>
<value>当前:⚠️开启遮罩</value>
</data>
<data name="TagNSFWOff" xml:space="preserve">
<value>#N___</value>
Expand All @@ -202,7 +202,7 @@
<value>#A___</value>
</data>
<data name="TagSpoilerOff" xml:space="preserve">
<value>🖼️禁用遮罩</value>
<value>当前:🖼️禁用遮罩</value>
</data>
<data name="ReviewReject" xml:space="preserve">
<value>❌拒绝</value>
Expand All @@ -211,10 +211,10 @@
<value>✅采用</value>
</data>
<data name="AnymouseOn" xml:space="preserve">
<value>👻匿名投稿</value>
<value>当前:👻匿名投稿</value>
</data>
<data name="AnymouseOff" xml:space="preserve">
<value>🤔保留来源</value>
<value>当前:🤔保留来源</value>
</data>
<data name="PostCancel" xml:space="preserve">
<value>❌取消</value>
Expand Down
9 changes: 9 additions & 0 deletions XinjingdailyBot.Interface/Data/IChannelOptionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ public interface IChannelOptionService : IBaseService<ChannelOptions>
/// <param name="channelChat"></param>
/// <returns></returns>
Task<EChannelOption> FetchChannelOption(Chat channelChat);
/// <summary>
/// 获取频道设定
/// </summary>
/// <param name="chatId"></param>
/// <param name="chatTitle"></param>
/// <param name="chatUserName"></param>
/// <returns></returns>
Task<EChannelOption> FetchChannelOption(long chatId, string chatTitle, string chatUserName);

/// <summary>
/// 更新频道设定
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion XinjingdailyBot.Interface/Helper/IMarkupHelperService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface IMarkupHelperService
/// <summary>
/// 一行显示的字数
/// </summary>
public static readonly int MaxLineCharsTag = 8;
public static readonly int MaxLineCharsTag = 10;
/// <summary>
/// 一行显示的字数
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion XinjingdailyBot.Model/Models/NewPosts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public sealed record NewPosts : BaseModel, IModifyAt, ICreateAt
/// 是否允许遮罩
/// </summary>
[SugarColumn(IsIgnore = true)]
public bool CanSpoiler => PostType == MessageType.Photo || PostType == MessageType.Video;
public bool CanSpoiler => PostType == MessageType.Photo || PostType == MessageType.Video || PostType == MessageType.Animation;

/// <summary>
/// 拒绝原因(如果拒绝)
Expand Down
1 change: 1 addition & 0 deletions XinjingdailyBot.Service/Bot/Common/ChannelService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public async Task InitChannelInfo()
catch
{
_logger.LogError("未找到指定的审核群组, 可以使用 /groupinfo 命令获取群组信息");
_reviewGroup = new Chat { Id = -1 };
}

if (channelOption.UseReviewLogMode)
Expand Down
31 changes: 31 additions & 0 deletions XinjingdailyBot.Service/Data/ChannelOptionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,37 @@ public async Task<EChannelOption> FetchChannelOption(Chat channelChat)
return channel.Option;
}

public async Task<EChannelOption> FetchChannelOption(long chatId,string chatTitle,string chatUserName)
{
var channel = await Queryable().Where(x => x.ChannelID == chatId).FirstAsync();
if (channel == null)
{
channel = new ChannelOptions {
ChannelID = chatId,
ChannelName = chatUserName ?? "",
ChannelTitle = chatTitle ?? "",
Option = EChannelOption.Normal,
Count = 1,
CreateAt = DateTime.Now,
ModifyAt = DateTime.Now,
};
await Insertable(channel).ExecuteCommandAsync();
}
else
{
if (channel.ChannelName != chatUserName || channel.ChannelTitle != chatTitle)
{
channel.ChannelTitle = chatTitle ?? "";
channel.ChannelName = chatUserName ?? "";
channel.ModifyAt = DateTime.Now;
}
channel.Count++;
await Updateable(channel).ExecuteCommandAsync();
}

return channel.Option;
}

public async Task<ChannelOptions?> FetchChannelByTitle(string channelTitle)
{
var channel = await Queryable().Where(x => x.ChannelTitle == channelTitle).FirstAsync();
Expand Down
68 changes: 35 additions & 33 deletions XinjingdailyBot.Service/Data/PostService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ public async Task HandleMediaGroupPosts(Users dbUser, Message message)
newPost.ReviewMsgID = newPost.OriginMsgID;
newPost.ReviewActionChatID = newPost.OriginActionChatID;
newPost.ReviewActionMsgID = newPost.OriginActionMsgID;
newPost.ReviewMediaGroupID = mediaGroupId;
}

postID = await Insertable(newPost).ExecuteReturnIdentityAsync();
Expand All @@ -466,15 +467,17 @@ public async Task HandleMediaGroupPosts(Users dbUser, Message message)
}
}

//更新附件
if (postID > 0)
{
//更新附件
var attachment = _attachmentService.GenerateAttachment(message, postID);

if (attachment != null)
{
await _attachmentService.Insertable(attachment).ExecuteCommandAsync();
}

//记录媒体组
await _mediaGroupService.AddPostMediaGroup(message);
}
}

Expand Down Expand Up @@ -548,13 +551,14 @@ public async Task RejetPost(NewPosts post, Users dbUser, RejectReasons rejectRea
{
var attachment = await _attachmentService.Queryable().Where(x => x.PostID == post.Id).FirstAsync();

var inputFile = new InputFileId(attachment.FileID);
var handler = post.PostType switch {
MessageType.Photo => _botClient.SendPhotoAsync(_channelService.RejectChannel.Id, new InputFileId(attachment.FileID)),
MessageType.Audio => _botClient.SendAudioAsync(_channelService.RejectChannel.Id, new InputFileId(attachment.FileID)),
MessageType.Video => _botClient.SendVideoAsync(_channelService.RejectChannel.Id, new InputFileId(attachment.FileID)),
MessageType.Voice => _botClient.SendVoiceAsync(_channelService.RejectChannel.Id, new InputFileId(attachment.FileID)),
MessageType.Document => _botClient.SendDocumentAsync(_channelService.RejectChannel.Id, new InputFileId(attachment.FileID)),
MessageType.Animation => _botClient.SendAnimationAsync(_channelService.RejectChannel.Id, new InputFileId(attachment.FileID)),
MessageType.Photo => _botClient.SendPhotoAsync(_channelService.RejectChannel.Id, inputFile),
MessageType.Audio => _botClient.SendAudioAsync(_channelService.RejectChannel.Id, inputFile),
MessageType.Video => _botClient.SendVideoAsync(_channelService.RejectChannel.Id, inputFile),
MessageType.Voice => _botClient.SendVoiceAsync(_channelService.RejectChannel.Id, inputFile),
MessageType.Document => _botClient.SendDocumentAsync(_channelService.RejectChannel.Id, inputFile),
MessageType.Animation => _botClient.SendAnimationAsync(_channelService.RejectChannel.Id, inputFile),
_ => throw new Exception("未知的稿件类型"),
};

Expand All @@ -575,16 +579,17 @@ public async Task RejetPost(NewPosts post, Users dbUser, RejectReasons rejectRea
{
attachmentType = post.PostType;
}
var inputFile = new InputFileId(attachments[i].FileID);
group[i] = attachmentType switch {
MessageType.Photo => new InputMediaPhoto(new InputFileId(attachments[i].FileID)),
MessageType.Audio => new InputMediaAudio(new InputFileId(attachments[i].FileID)),
MessageType.Video => new InputMediaVideo(new InputFileId(attachments[i].FileID)),
MessageType.Voice => new InputMediaAudio(new InputFileId(attachments[i].FileID)),
MessageType.Document => new InputMediaDocument(new InputFileId(attachments[i].FileID)),
MessageType.Photo => new InputMediaPhoto(inputFile),
MessageType.Audio => new InputMediaAudio(inputFile),
MessageType.Video => new InputMediaVideo(inputFile),
MessageType.Voice => new InputMediaAudio(inputFile),
MessageType.Document => new InputMediaDocument(inputFile),
_ => throw new Exception("未知的稿件类型"),
};
}
var postMessages = await _botClient.SendMediaGroupAsync(_channelService.RejectChannel.Id, group);
var postMessages = await _botClient.SendMediaGroupAsync(_channelService.RejectChannel, group);

var postMessage = postMessages.FirstOrDefault();
if (postMessage != null)
Expand Down Expand Up @@ -631,11 +636,6 @@ public async Task AcceptPost(NewPosts post, Users dbUser, bool inPlan, CallbackQ
{
var poster = await _userService.Queryable().FirstAsync(x => x.UserID == post.PosterUID);

if (post.IsDirectPost)
{
poster.PostCount++;
}

ChannelOptions? channel = null;
if (post.IsFromChannel)
{
Expand Down Expand Up @@ -665,13 +665,14 @@ public async Task AcceptPost(NewPosts post, Users dbUser, bool inPlan, CallbackQ
{
var attachment = await _attachmentService.Queryable().FirstAsync(x => x.PostID == post.Id);

var inputFile = new InputFileId(attachment.FileID);
var handler = post.PostType switch {
MessageType.Photo => _botClient.SendPhotoAsync(_channelService.AcceptChannel.Id, new InputFileId(attachment.FileID), caption: postText, parseMode: ParseMode.Html, hasSpoiler: hasSpoiler),
MessageType.Audio => _botClient.SendAudioAsync(_channelService.AcceptChannel.Id, new InputFileId(attachment.FileID), caption: postText, parseMode: ParseMode.Html, title: attachment.FileName),
MessageType.Video => _botClient.SendVideoAsync(_channelService.AcceptChannel.Id, new InputFileId(attachment.FileID), caption: postText, parseMode: ParseMode.Html, hasSpoiler: hasSpoiler),
MessageType.Voice => _botClient.SendVoiceAsync(_channelService.AcceptChannel.Id, new InputFileId(attachment.FileID), caption: postText, parseMode: ParseMode.Html),
MessageType.Document => _botClient.SendDocumentAsync(_channelService.AcceptChannel.Id, new InputFileId(attachment.FileID), caption: postText, parseMode: ParseMode.Html),
MessageType.Animation => _botClient.SendDocumentAsync(_channelService.AcceptChannel.Id, new InputFileId(attachment.FileID), caption: postText, parseMode: ParseMode.Html),
MessageType.Photo => _botClient.SendPhotoAsync(_channelService.AcceptChannel.Id, inputFile, caption: postText, parseMode: ParseMode.Html, hasSpoiler: hasSpoiler),
MessageType.Audio => _botClient.SendAudioAsync(_channelService.AcceptChannel.Id, inputFile, caption: postText, parseMode: ParseMode.Html, title: attachment.FileName),
MessageType.Video => _botClient.SendVideoAsync(_channelService.AcceptChannel.Id, inputFile, caption: postText, parseMode: ParseMode.Html, hasSpoiler: hasSpoiler),
MessageType.Voice => _botClient.SendVoiceAsync(_channelService.AcceptChannel.Id, inputFile, caption: postText, parseMode: ParseMode.Html),
MessageType.Document => _botClient.SendDocumentAsync(_channelService.AcceptChannel.Id, inputFile, caption: postText, parseMode: ParseMode.Html),
MessageType.Animation => _botClient.SendAnimationAsync(_channelService.AcceptChannel.Id, inputFile, caption: postText, parseMode: ParseMode.Html, hasSpoiler: hasSpoiler),
_ => null,
};

Expand All @@ -696,13 +697,15 @@ public async Task AcceptPost(NewPosts post, Users dbUser, bool inPlan, CallbackQ
{
attachmentType = post.PostType;
}

var inputFile = new InputFileId(attachments[i].FileID);
group[i] = attachmentType switch {
MessageType.Photo => new InputMediaPhoto(new InputFileId(attachments[i].FileID)) { Caption = i == 0 ? postText : null, ParseMode = ParseMode.Html, HasSpoiler = hasSpoiler },
MessageType.Audio => new InputMediaAudio(new InputFileId(attachments[i].FileID)) { Caption = i == 0 ? postText : null, ParseMode = ParseMode.Html },
MessageType.Video => new InputMediaVideo(new InputFileId(attachments[i].FileID)) { Caption = i == 0 ? postText : null, ParseMode = ParseMode.Html, HasSpoiler = hasSpoiler },
MessageType.Voice => new InputMediaVideo(new InputFileId(attachments[i].FileID)) { Caption = i == 0 ? postText : null, ParseMode = ParseMode.Html },
MessageType.Document => new InputMediaDocument(new InputFileId(attachments[i].FileID)) { Caption = i == attachments.Count - 1 ? postText : null, ParseMode = ParseMode.Html },
_ => throw new Exception(),
MessageType.Photo => new InputMediaPhoto(inputFile) { Caption = i == 0 ? postText : null, ParseMode = ParseMode.Html, HasSpoiler = hasSpoiler },
MessageType.Audio => new InputMediaAudio(inputFile) { Caption = i == 0 ? postText : null, ParseMode = ParseMode.Html },
MessageType.Video => new InputMediaVideo(inputFile) { Caption = i == 0 ? postText : null, ParseMode = ParseMode.Html, HasSpoiler = hasSpoiler },
MessageType.Voice => new InputMediaVideo(inputFile) { Caption = i == 0 ? postText : null, ParseMode = ParseMode.Html },
MessageType.Document => new InputMediaDocument(inputFile) { Caption = i == attachments.Count - 1 ? postText : null, ParseMode = ParseMode.Html },
_ => throw new Exception("未知的稿件类型"),
};
}

Expand Down Expand Up @@ -738,7 +741,7 @@ public async Task AcceptPost(NewPosts post, Users dbUser, bool inPlan, CallbackQ
string reviewMsg = _textHelperService.MakeReviewMessage(poster, dbUser, post.Anonymous);
await _botClient.EditMessageTextAsync(callbackQuery.Message!, reviewMsg, parseMode: ParseMode.Html, disableWebPagePreview: true);
}
else //直接投稿, 在审核群留档
else // 直接投稿, 在审核群留档
{
string reviewMsg = _textHelperService.MakeReviewMessage(poster, post.PublicMsgID, post.Anonymous);
var msg = await _botClient.SendTextMessageAsync(_channelService.ReviewGroup.Id, reviewMsg, parseMode: ParseMode.Html, disableWebPagePreview: true);
Expand All @@ -756,7 +759,6 @@ public async Task AcceptPost(NewPosts post, Users dbUser, bool inPlan, CallbackQ

//通知投稿人
string posterMsg = _textHelperService.MakeNotification(post.IsDirectPost, inPlan, post.PublicMsgID);

if (poster.Notification && poster.UserID != dbUser.UserID)//启用通知并且审核与投稿不是同一个人
{
//单独发送通知消息
Expand Down
3 changes: 1 addition & 2 deletions XinjingdailyBot.Service/Data/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,7 @@ private async Task AutoLeaveChat(Chat? msgChat)
//如果是配置文件中指定的管理员就覆盖用户组权限
if (_optionsSetting.Bot.SuperAdmins?.Contains(dbUser.UserID) ?? false)
{
var maxGroupID = _groupRepository.GetMaxGroupId();
dbUser.GroupID = maxGroupID;
dbUser.GroupID = _groupRepository.GetMaxGroupId();
}

//根据GroupID设置用户权限信息 (封禁用户区别对待)
Expand Down
Loading

0 comments on commit e8e3ed5

Please sign in to comment.