diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml index c66de99..f7ca409 100644 --- a/.github/workflows/build-image.yml +++ b/.github/workflows/build-image.yml @@ -33,7 +33,7 @@ jobs: name: Build and push uses: docker/build-push-action@v2 with: - platforms: linux/amd64,linux/arm64 + platforms: linux/amd64 push: ${{ github.ref == 'refs/heads/dev' }} tags: ${{ secrets.REGISTRY_URL }}/west/telegram-bot:latest, ${{ secrets.REGISTRY_URL }}/west/telegram-bot:${{ steps.commit_sha.outputs.sha_short }} \ No newline at end of file diff --git a/modules/ChatManagement/Handler/Rules.cs b/modules/ChatManagement/Handler/Rules.cs new file mode 100644 index 0000000..e6bc472 --- /dev/null +++ b/modules/ChatManagement/Handler/Rules.cs @@ -0,0 +1,46 @@ +using System.Threading.Tasks; +using BotFramework.Attributes; +using BotFramework.Enums; +using Kruzya.TelegramBot.Core.Data; +using Kruzya.TelegramBot.Core.Extensions; +using Telegram.Bot; +using Telegram.Bot.Exceptions; + +namespace West.TelegramBot.ChatManagement.Handler +{ + internal class Rules : ManagementHandler + { + [Command(InChat.Public, "setrules", CommandParseMode.Both)] + public async Task HandleSetRules() + { + var replyToMessage = Message?.ReplyToMessage; + + if (replyToMessage == null || !await CanPunish()) return; + + var opt = await Db.UserValues.FindOrCreateOption(Chat.Id, "rulesMsgId"); + opt.SetValue(replyToMessage.MessageId); + Db.MarkAsModified(opt); + } + + [Command(InChat.Public, "rules", CommandParseMode.Both)] + public async Task HandleRules() + { + var opt = await Db.UserValues.FindOption(Chat.Id, "rulesMsgId"); + if (opt == null) + { + return; + } + + try + { + await Bot.CopyMessageAsync(Chat.Id, Chat.Id, opt.GetValue()); + } + catch (ApiRequestException) + { + Db.MarkAsDeleted(opt); + } + } + + public Rules(CoreContext db) : base(db) {} + } +} \ No newline at end of file