Esempio n. 1
0
        private async Task onAdminCallback(ITelegramBotClient botClient, Update e, CancellationToken cancellationToken)
        {
            if (e.CallbackQuery.Data != null)
            {
                DRaumCallbackData callbackData = DRaumCallbackData.parseCallbackData(e.CallbackQuery.Data);
                if (callbackData.getPrefix().Equals(Keyboards.GenericMessageDeletePrefix))
                {
                    await this.adminBot.removeMessage(e.CallbackQuery.Message.MessageId);

                    return;
                }
                if (callbackData.getPrefix().Equals(Keyboards.ModDeleteFlaggedPrefix))
                {
                    // Der Admin entscheidet den geflaggten Post zu entfernen
                    long postingID       = callbackData.getId();
                    int  messageId       = this.posts.getMessageId(postingID);
                    int  messageIdDaily  = this.posts.getMessageIdDaily(postingID);
                    int  messageIdWeekly = this.posts.getMessageIdWeekly(postingID);
                    if (!this.posts.removePost(postingID))
                    {
                        logger.Error("Konnte den Post " + postingID + " nicht aus dem Datensatz löschen");
                    }
                    await this.adminBot.sendMessageWithKeyboard("Bitte manuell löschen",
                                                                Keyboards.getPostLinkWithCustomText(messageId, DRaumManager.Roomname, "Link zum D-Raum"));

                    if (messageIdDaily != -1)
                    {
                        await this.adminBot.sendMessageWithKeyboard("Bitte manuell löschen",
                                                                    Keyboards.getPostLinkWithCustomText(messageIdDaily, DRaumManager.Roomname_daily, "Link zum D-Raum-Daily"));
                    }
                    if (messageIdWeekly != -1)
                    {
                        await this.adminBot.sendMessageWithKeyboard("Bitte manuell löschen",
                                                                    Keyboards.getPostLinkWithCustomText(messageIdWeekly, DRaumManager.Roomname_weekly, "Link zum D-Raum-Daily"));
                    }
                    // Nachricht aus dem Admin-Chat löschen
                    await this.adminBot.removeMessage(e.CallbackQuery.Message.MessageId);

                    return;
                }
                if (callbackData.getPrefix().Equals(Keyboards.ModClearFlagPrefix))
                {
                    // Der Admin entscheided, den Flag zurückzunehmen
                    if (this.posts.removeFlagFromPost(callbackData.getId()))
                    {
                        await this.adminBot.removeMessage(e.CallbackQuery.Message.MessageId);

                        await this.adminBot.replyToCallback(e.CallbackQuery.Id, "Flag wurde entfernt");
                    }
                    else
                    {
                        logger.Error("Konnte das Flag vom Post nicht entfernen: " + callbackData.getId());
                    }
                }
            }
        }
Esempio n. 2
0
        // == == CALLBACKS == ==

        private async Task onFeedbackCallback(ITelegramBotClient botClient, Update e, CancellationToken cancellationToken)
        {
            if (e.Type == UpdateType.Message)
            {
                // Message
                if (e.Message.Text == null)
                {
                    return;
                }
                if (this.feedbackManager.isWaitingForFeedbackReply())
                {
                    long chatId = this.feedbackManager.processFeedbackReplyAndGetChatId();
                    await this.inputBot.sendMessage(chatId,
                                                    "Eine Antwort des Kanalbetreibers auf Ihr Feedback:\r\n\r\n" + e.Message.Text);

                    await this.feedbackBot.sendMessage("Feedback-Antwort ist verschickt");
                }
            }
            if (e.Type == UpdateType.CallbackQuery)
            {
                // Callback Query
                if (e.CallbackQuery.Data != null)
                {
                    DRaumCallbackData callbackData = DRaumCallbackData.parseCallbackData(e.CallbackQuery.Data);
                    if (callbackData.getPrefix().Equals(Keyboards.ModBlockPrefix))
                    {
                        // verwerfen des feedbacks
                        await this.feedbackBot.removeInlineMarkup(e.CallbackQuery.Message.MessageId);

                        return;
                    }
                    if (callbackData.getPrefix().Equals(Keyboards.ModAcceptPrefix))
                    {
                        // Antworten auf das Feedback
                        this.feedbackManager.enableWaitForFeedbackReply(callbackData.getId());
                        await this.feedbackBot.sendMessage("Der nächste eingegebene Text wird an den Autor gesendet");
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Der Nutzer hat einen Beitrag mit Buttons bekommen und muss entscheiden, ob der Beitrag gepostet wird oder nicht
        /// </summary>
        private async Task onInputBotCallback(ITelegramBotClient botClient, Update e, CancellationToken cancellationToken)
        {
            if (e.Type == UpdateType.CallbackQuery)
            {
                if (e.CallbackQuery.Data != null)
                {
                    DRaumCallbackData callbackData = DRaumCallbackData.parseCallbackData(e.CallbackQuery.Data);
                    if (callbackData.getPrefix().Equals(Keyboards.ModAcceptPrefix))
                    {
                        if (this.acceptPostForPublishing(callbackData.getId()).Result)
                        {
                            await this.inputBot.sendMessage(e.CallbackQuery.From.Id, "Der Beitrag ist angenommen");

                            await this.inputBot.removeMessage(e.CallbackQuery.Message.MessageId, e.CallbackQuery.From.Id);
                        }
                        else
                        {
                            await this.inputBot.sendMessage(e.CallbackQuery.From.Id,
                                                            "Post konnte nicht veröffentlicht werden. Probieren Sie es nochmal. Falls es wiederholt fehlschlägt, wenden Sie sich an den Administrator.");
                        }
                        return;
                    }
                    if (callbackData.getPrefix().Equals(Keyboards.ModBlockPrefix))
                    {
                        if (!this.posts.removePost(callbackData.getId()))
                        {
                            logger.Error("Konnte den Post nicht aus dem Datensatz löschen: " + callbackData.getId());
                        }
                        await this.inputBot.removeMessage(e.CallbackQuery.Message.MessageId, e.CallbackQuery.From.Id);

                        await this.inputBot.sendMessage(e.CallbackQuery.From.Id, "Der Post wird nicht veröffentlicht und verworfen.");

                        return;
                    }
                    if (callbackData.getPrefix().Equals(Keyboards.ModeWritePrefix))
                    {
                        await this.inputBot.switchToWriteMode(e.CallbackQuery.From.Id, e.CallbackQuery.From.Username,
                                                              e.CallbackQuery.From.Id);

                        return;
                    }
                    if (callbackData.getPrefix().Equals(Keyboards.ModeFeedbackPrefix))
                    {
                        await this.inputBot.switchToFeedbackMode(e.CallbackQuery.From.Id, e.CallbackQuery.From.Username,
                                                                 e.CallbackQuery.From.Id);
                    }
                }
            }
            if (e.Type == UpdateType.Message)
            {
                if (e.Message.Text != null)
                {
                    // Empfängerprüfung und Spam-Block
                    // Dieser Block wirft auch eine Exception, wenn die maximale Nutzerzahl erreicht ist
                    try
                    {
                        if (!this.authors.isCoolDownOver(e.Message.From.Id, e.Message.From.Username, Author.InteractionCooldownTimer.Default))
                        {
                            TimeSpan coolDownTime = this.authors.getCoolDownTimer(e.Message.From.Id, e.Message.From.Username, Author.InteractionCooldownTimer.Default);
                            await this.inputBot.sendMessage(e.Message.From.Id,
                                                            "⏳ (Spamvermeidung) Zeit bis zur nächsten Bot-Interaktion: " + coolDownTime.TotalMinutes.ToString("0.0") +
                                                            " Minute(n)");

                            return;
                        }
                    }
                    catch (DRaumException dre)
                    {
                        await this.inputBot.sendMessage(e.Message.From.Id, "Ein Fehler trat auf: " + dre.Message);

                        return;
                    }
                    if (e.Message.Text.Equals("/" + Writecommand))
                    {
                        await this.inputBot.switchToWriteMode(e.Message.From.Id, e.Message.From.Username, e.Message.Chat.Id);

                        return;
                    }
                    if (e.Message.Text.Equals("/" + Feedbackcommand))
                    {
                        await this.inputBot.switchToFeedbackMode(e.Message.From.Id, e.Message.From.Username, e.Message.Chat.Id);

                        return;
                    }
                    if (this.authors.isFeedbackMode(e.Message.From.Id, e.Message.From.Username) ||
                        this.authors.isPostMode(e.Message.From.Id, e.Message.From.Username))
                    {
                        string text = Utilities.telegramEntitiesToHtml(e.Message.Text, e.Message.Entities);
                        await this.inputBot.processTextInput(e.Message.From.Id, e.Message.From.Username, e.Message.Chat.Id, text);
                    }
                    else
                    {
                        // Kein Modus
                        await this.inputBot.sendMessageWithKeyboard(e.Message.From.Id, NoModeChosen, Keyboards.getChooseInputModeKeyboard());
                    }
                }
            }
        }
Esempio n. 4
0
        private async Task onPublishCallback(ITelegramBotClient botClient, Update e, CancellationToken cancellationToken)
        {
            try
            {
                if (e.CallbackQuery.Data != null)
                {
                    // Auswerten: Vote-up, Vote-down, Flag
                    DRaumCallbackData callbackData = DRaumCallbackData.parseCallbackData(e.CallbackQuery.Data);
                    if (callbackData.getPrefix().Equals(Keyboards.VoteUpPrefix))
                    {
                        // UPVOTE
                        string responseText = "Stimme bereits abgegeben oder eigener Post";
                        if (this.canUserVote(callbackData.getId(), e.CallbackQuery.From.Id, e.CallbackQuery.From.Username))
                        {
                            int votecount = this.authors.voteUpAndGetCount(e.CallbackQuery.From.Id, e.CallbackQuery.From.Username);
                            if (votecount != 0)
                            {
                                this.statistics.increaseInteraction();
                                this.authors.updateCredibility(this.posts.getAuthorId(callbackData.getId()), votecount, 0);
                                this.upvote(callbackData.getId(), e.CallbackQuery.From.Id, votecount);
                                responseText = "Positivstimme erhalten";
                            }
                            else
                            {
                                responseText = "Fehler beim Abstimmen!";
                            }
                        }

                        await this.publishBot.answerCallback(e.CallbackQuery.Id, responseText);

                        return;
                    }
                    if (callbackData.getPrefix().Equals(Keyboards.VoteDownPrefix))
                    {
                        // DOWNVOTE
                        string responseText = "Stimme bereits abgegeben oder eigener Post";
                        if (this.canUserVote(callbackData.getId(), e.CallbackQuery.From.Id, e.CallbackQuery.From.Username))
                        {
                            int votecount = this.authors.voteDownAndGetCount(e.CallbackQuery.From.Id, e.CallbackQuery.From.Username);
                            if (votecount != 0)
                            {
                                this.statistics.increaseInteraction();
                                this.authors.updateCredibility(this.posts.getAuthorId(callbackData.getId()), 0, votecount);
                                this.downvote(callbackData.getId(), e.CallbackQuery.From.Id, votecount);
                                responseText = "Negativstimme erhalten";
                            }
                            else
                            {
                                responseText = "Fehler beim Abstimmen!";
                            }
                        }
                        await this.publishBot.answerCallback(e.CallbackQuery.Id, responseText);

                        return;
                    }
                    if (callbackData.getPrefix().Equals(Keyboards.FlagPrefix))
                    {
                        // Flagging
                        if (!this.authors.isCoolDownOver(e.CallbackQuery.From.Id, e.CallbackQuery.From.Username, Author.InteractionCooldownTimer.Flagging))
                        {
                            TimeSpan coolDownTime = this.authors.getCoolDownTimer(e.CallbackQuery.From.Id,
                                                                                  e.CallbackQuery.From.Username, Author.InteractionCooldownTimer.Flagging);
                            string msgCoolDownText = "(Spamvermeidung) Zeit bis zur nächsten Markiermöglichkeit: " +
                                                     coolDownTime.TotalMinutes.ToString("0.0") + " Minute(n)";
                            if (coolDownTime.TotalMinutes > 180)
                            {
                                msgCoolDownText = "(Spamvermeidung) Zeit bis zur nächsten Markiermöglichkeit: " +
                                                  coolDownTime.TotalHours.ToString("0.0") + " Stunde(n)";
                            }
                            await this.publishBot.answerCallback(e.CallbackQuery.Id, msgCoolDownText);

                            return;
                        }
                        string responseText = "Beitrag bereits markiert oder eigener Post";
                        if (this.canUserFlag(callbackData.getId(), e.CallbackQuery.From.Id, e.CallbackQuery.From.Username))
                        {
                            this.statistics.increaseInteraction();
                            this.authors.resetCoolDown(e.CallbackQuery.From.Id, e.CallbackQuery.From.Username, Author.InteractionCooldownTimer.Flagging);
                            this.flag(callbackData.getId(), e.CallbackQuery.From.Id);
                            responseText = "Beitrag für Moderation markiert";
                        }
                        await this.publishBot.answerCallback(e.CallbackQuery.Id, responseText);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Genereller Fehler");
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Diese Funktion verarbeitet das Drücken der Knöpfe im Moderations-Bot
        /// </summary>
        private async Task onModerateCallback(ITelegramBotClient botClient, Update e, CancellationToken cancellationToken)
        {
            if (e.Type == UpdateType.CallbackQuery)
            {
                if (e.CallbackQuery.Data == null)
                {
                    return;
                }
                DRaumCallbackData callbackData = DRaumCallbackData.parseCallbackData(e.CallbackQuery.Data);
                // ==  Der Moderator akzeptiert den Beitrag
                if (callbackData.getPrefix().Equals(Keyboards.ModAcceptPrefix))
                {
                    if (this.acceptPostForPublishing(callbackData.getId()).Result)
                    {
                        // Message not needed anymore, delete
                        await this.moderateBot.removeMessage(e.CallbackQuery.Message.MessageId);

                        await this.moderateBot.replyToCallback(e.CallbackQuery.Id, "Beitrag wird freigegeben");
                    }
                    else
                    {
                        await this.moderateBot.replyToCallback(e.CallbackQuery.Id, "Konnte den Post nicht freigeben...");
                    }
                    return;
                }
                // ==  Der Moderator will den Beitrag bearbeiten und zurücksenden
                if (callbackData.getPrefix().Equals(Keyboards.ModEditPrefix))
                {
                    await this.moderateBot.editMessageButtons(e.CallbackQuery.Message.MessageId,
                                                              Keyboards.getGotItDeleteButtonKeyboard());

                    this.feedbackManager.waitForModerationText(callbackData.getId());
                    await this.moderateBot.replyToCallback(e.CallbackQuery.Id, "Editierten Beitrag abschicken");

                    return;
                }
                // ==  Der Moderator lehnt den Beitrag ab
                if (callbackData.getPrefix().Equals(Keyboards.ModBlockPrefix))
                {
                    // Nachricht entfernen
                    await this.moderateBot.removeMessage(e.CallbackQuery.Message.MessageId);

                    this.feedbackManager.waitForDenyingText(callbackData.getId());
                    await this.moderateBot.sendMessageWithKeyboard("Begründung schreiben und abschicken",
                                                                   Keyboards.getGotItDeleteButtonKeyboard(), false);

                    return;
                }
                if (callbackData.getPrefix().Equals(Keyboards.GenericMessageDeletePrefix))
                {
                    await this.moderateBot.removeMessage(e.CallbackQuery.Message.MessageId);

                    return;
                }
                if (callbackData.getPrefix().Equals(Keyboards.ModGetNextCheckPostPrefix))
                {
                    KeyValuePair <long, string> postingPair = this.posts.getNextPostToCheck();
                    if (postingPair.Key == -1)
                    {
                        return;
                    }
                    Message msg = await this.moderateBot.sendMessageWithKeyboard(postingPair.Value,
                                                                                 Keyboards.getModeratePostKeyboard(postingPair.Key), true);

                    if (msg != null)
                    {
                        return;
                    }
                    // keine Nachricht, wieder neu einreihen
                    if (this.posts.putBackIntoQueue(postingPair.Key))
                    {
                        return;
                    }
                    logger.Error("Konnte den Post nicht wieder einfügen, wird gelöscht:" + postingPair.Key + " TEXT:" + postingPair.Value);
                    Posting posting = this.posts.removePostFromInCheck(postingPair.Key);
                    if (posting != null)
                    {
                        await this.inputBot.sendMessage(posting.getAuthorId(),
                                                        "Dieser Beitrag konnte aufgrund interner Fehler nicht bearbeitet werden:  " +
                                                        posting.getPostingText() +
                                                        "\r\n\r\nBitte nochmal probieren. Sollte der Fehler weiterhin bestehen, bitte an einen Administrator wenden.");
                    }
                    else
                    {
                        logger.Error("Der Post konnte nicht gelöscht werden: " + postingPair.Key);
                    }
                    return;
                }
                if (callbackData.getPrefix().Equals(Keyboards.ModBlockUser3Days))
                {
                    await this.moderateBot.removeMessage(e.CallbackQuery.Message.MessageId);

                    this.feedbackManager.waitForAuthorBlockText(callbackData.getId(), 3);
                    await this.moderateBot.sendMessageWithKeyboard("Begründung für 3 TAGE BLOCK schreiben und abschicken",
                                                                   Keyboards.getGotItDeleteButtonKeyboard(), false);

                    return;
                }
                if (callbackData.getPrefix().Equals(Keyboards.ModBlockUser7Days))
                {
                    await this.moderateBot.removeMessage(e.CallbackQuery.Message.MessageId);

                    this.feedbackManager.waitForAuthorBlockText(callbackData.getId(), 7);
                    await this.moderateBot.sendMessageWithKeyboard("Begründung für 7 TAGE BLOCK! schreiben und abschicken",
                                                                   Keyboards.getGotItDeleteButtonKeyboard(), false);

                    return;
                }
                if (callbackData.getPrefix().Equals(Keyboards.ModBlockUser30Days))
                {
                    await this.moderateBot.removeMessage(e.CallbackQuery.Message.MessageId);

                    this.feedbackManager.waitForAuthorBlockText(callbackData.getId(), 30);
                    await this.moderateBot.sendMessageWithKeyboard("Begründung für 30 TAGE BLOCK!!! schreiben und abschicken",
                                                                   Keyboards.getGotItDeleteButtonKeyboard(), false);
                }
            }
            if (e.Type == UpdateType.Message)
            {
                if (e.Message.Text == null)
                {
                    return;
                }
                if (this.feedbackManager.isWaitingForModeratedText())
                {
                    // Den moderierten Text dem Nutzer zum bestätigen zuschicken.
                    long postingId = this.feedbackManager.getNextModeratedPostId();
                    if (this.posts.isPostingInCheck(postingId))
                    {
                        this.posts.updatePostText(postingId, e.Message.Text, true);
                        await this.inputBot.sendMessageWithKeyboard(
                            this.posts.getAuthorId(postingId),
                            "MODERIERTER TEXT:\r\n\r\n" + this.posts.getPostingTextFromInCheck(postingId),
                            Keyboards.getAcceptDeclineModeratedPostKeyboard(postingId));

                        this.feedbackManager.resetProcessModerationText();
                        await this.moderateBot.sendMessageWithKeyboard(
                            "Geänderter Text ist dem Autor zugestellt.", Keyboards.getGotItDeleteButtonKeyboard(),
                            false);

                        await this.moderateBot.removeMessage(e.Message.MessageId);
                    }
                    else
                    {
                        logger.Error("Konnte den zu editierenden Post nicht laden: " + this.feedbackManager.getNextModeratedPostId());
                        await this.moderateBot.sendMessageWithKeyboard(
                            "Der zu editierende Post wurde nicht gefunden. Nochmal den Text abschicken. Wenn der Fehler bestehen bleibt, einen Administrator informieren",
                            Keyboards.getGotItDeleteButtonKeyboard(),
                            false);
                    }
                    return;
                }
                if (this.feedbackManager.isWaitingForDenyText())
                {
                    // Die Begründung dem Nutzer zuschicken.
                    long postingId = this.feedbackManager.getNextModeratedPostId();
                    if (this.posts.isPostingInCheck(postingId))
                    {
                        string teaser = this.posts.getPostingTeaser(postingId);
                        await this.inputBot.sendMessage(this.posts.getAuthorId(postingId),
                                                        "Der Beitrag wurde durch Moderation abgelehnt. Begründung:\r\n" +
                                                        e.Message.Text + "\r\n\r\nBeitragsvorschau: " + teaser);

                        this.feedbackManager.resetProcessModerationText();
                        this.posts.discardPost(postingId);
                    }
                }
                if (this.feedbackManager.isWaitingForAuthorBlockingText())
                {
                    // Dem Nutzer die Begründung für den Block schicken
                    long   postingId = this.feedbackManager.getNextModeratedPostId();
                    long   authorId  = this.posts.getAuthorId(postingId);
                    int    days      = this.feedbackManager.getBlockDays();
                    string teaser    = this.posts.getPostingTeaser(postingId);
                    this.authors.blockForDays(authorId, days);
                    await this.inputBot.sendMessage(authorId,
                                                    "Ihre Beitrag-Schreibe-Möglichkeit ist nun für " + days + " Tage gesperrt. Begründung:\r\n" +
                                                    e.Message.Text + "\r\n\r\nBasierend auf dem Beitrag: " + teaser);

                    this.feedbackManager.resetProcessModerationText();
                    this.posts.discardPost(postingId);
                }
            }
        }