public void Send(string apikey, Strings strings, long chatId, bool fromChannel = false) { dBHandler.AddToQueue(this, false); this.archived = true; ContentParts content = GetContent(strings, apikey); Api.SendMessage(apikey, chatId, content.Text, replyMarkup: (fromChannel ? content.InlineKeyboard : GenerateUserMarkup(strings, apikey))); }
public async Task <bool> Update(List <Instance> instances, Strings strings, QueueObject queueObject) { bool allDone = false; Instance currentInstance = instances.Find(x => x.chatID == queueObject.FromBotID) /*?? instances.Find()*/; ContentParts content = GetContent(strings); ContentParts contentChannel = GetContent(strings, channel: true); foreach (MessageID messageID in messageIds) { if (messageID.messageIDInvalid) { continue; } ContentParts contentToSend = messageID.channel ? contentChannel : content; Instance currentLoopInstance = currentInstance; bool instanceQuestionable = false; try { currentLoopInstance = instances.Find(x => x.chatID == messageID.botChatID); } catch (NullReferenceException) { instanceQuestionable = true; } if (currentLoopInstance == null) { instanceQuestionable = true; continue; } if (RequestHandler.DoUpdate(instance: currentLoopInstance, messageID: messageID, messageTextLength: content.Text.Length, necessary: queueObject.Important)) { try { await Api.EditMessageTextAsync( currentLoopInstance.apikey, contentToSend.Text, contentToSend.InlineKeyboard, inlineMessageID : messageID.inlineMessageId ); messageID.Last30Updates.Add(DateTime.Now); queueObject.DoneUpdates.Add(messageID.inlineMessageId); if (instanceQuestionable) { messageID.botChatID = currentLoopInstance.chatID; } //Thrown when the message was deleted } catch (WJClubBotFrame.Exceptions.MessageIDInvalid) { messageID.messageIDInvalid = true; } catch (WJClubBotFrame.Exceptions.TooManyRequests ex) { currentLoopInstance.retryAt = DateTime.Now + TimeSpan.FromSeconds(ex.RetryAfter); } } else { allDone = false; continue; } } return(allDone); }
public InlineQueryResultArticle Result(Strings strings, string apikey, bool channel) { if (closed) { return(null); } ContentParts content = GetContent(strings, apikey, noApproximation: true /*TODO Request handler here*/, channel: channel); return(InlineQueryResultArticle.Create(chatId + ":" + pollId, content.InlineTitle, InputTextMessageContent.Create(content.Text, disableWebPagePreview: true), content.InlineKeyboard, description: content.InlineDescription, thumbUrl: "https://wjclub.capella.uberspace.de/groupagreebot/res/" + pollType.ToString() + "_" + anony.ToString() + ".png", thumbWidth: 256, thumbHeight: 256)); }
protected override ContentParts GetContent(Strings strings, string apikey, bool channel = false, int?offset = default(int?), bool moderatePane = true) { ContentParts content = base.GetContent(strings, apikey, channel, offset); Strings.langs oldLang = strings.CurrentLang; strings.SetLanguage(this.lang); content.Text += "\nℹ️ " + string.Format(strings.GetString(Strings.stringsList.limitedDoodleYouCanChooseSoMany), MaxVotes, pollVotes.Count); strings.SetLanguage(oldLang); return(content); }
public InlineQueryResultArticle Result(Strings strings, string apikey, bool channel) { if (closed) { return(null); } ContentParts content = GetContent(strings, apikey, channel); return(InlineQueryResultArticle.Create(chatId + ":" + pollId, pollText, InputTextMessageContent.Create(content.Text, disableWebPagePreview: true), content.InlineKeyboard, description: content.Description, thumbUrl: "https://bots.wjclub.tk/groupagreebot/res/" + pollType.ToString() + "_" + anony.ToString() + ".png", thumbWidth: 256, thumbHeight: 256)); }
public async Task Update(List <Instance> instances, long currentBotChatID, Strings strings, bool noApproximation, string currentInlineMessageID = null, int?messageId = null, string currentText = null, long?newChatId = null, bool voteButtonPressed = false) { //If a user pressed the update button, the messageId is not null (so nobody voted) bool getsAVote = messageId == null; Instance currentInstance = instances.Find(x => x.chatID == currentBotChatID); string apikey = currentInstance.apikey; //Fully fledged poll ContentParts content = GetContent(strings, apikey, noApproximation: noApproximation); //Has only link buttons ContentParts contentChannel = GetContent(strings, apikey, noApproximation: noApproximation, channel: true); //Filters HTML-Tags from the new message to compare with the old message text (to reduce unecessary updates) Regex regex = new Regex("<[^>]*>"); if (currentText == null || regex.Replace(content.Text, "") != regex.Replace(currentText, "") || voteButtonPressed) { if (messageId != null) { //User voted in private chat and is not the poll owner if (newChatId != null && newChatId != this.chatId) { await Api.EditMessageTextAsync(apikey, strings.GetString(Strings.StringsList.votedSuccessfully), null, newChatId, messageId); getsAVote = true; //User requests to vote on his own poll } else if (voteButtonPressed) { await Api.EditMessageTextAsync(apikey, content.Text, content.InlineKeyboard, this.chatId, messageId); //Poll owner voted in private chat } else { await Api.EditMessageTextAsync(apikey, content.Text, GenerateUserMarkup(strings, apikey), this.chatId, messageId); getsAVote = true; } } //Refreshes all messages shared via inline mode if (getsAVote) { await RefreshInlineMessage(instances, currentBotChatID, content, contentChannel, currentInlineMessageID); } } }
public void Update(string apikey, Strings strings, int?messageId = null, string currentText = null, long?newChatId = null, bool vote = false) { bool getsAVote = messageId == null; ContentParts content = GetContent(strings, apikey); ContentParts contentChannel = GetContent(strings, apikey, true); Regex regex = new Regex("<[^>]*>"); if (currentText == null || regex.Replace(content.Text, "") != regex.Replace(currentText, "") || vote) { if (messageId != null) { if (newChatId != null && newChatId != chatId) { Api.EditMessageText(apikey, strings.GetString(Strings.stringsList.votedSuccessfully), null, newChatId, messageId); getsAVote = true; } else if (vote) { Api.EditMessageText(apikey, content.Text, content.InlineKeyboard, chatId, messageId); } else { Api.EditMessageText(apikey, content.Text, GenerateUserMarkup(strings, apikey), chatId, messageId); getsAVote = true; } } if (getsAVote) { foreach (MessageID messageID in messageIds) { if (messageID.channel) { Api.EditMessageText(apikey, contentChannel.Text, contentChannel.InlineKeyboard, inlineMessageId: messageID.inlineMessageId); } else { Api.EditMessageText(apikey, content.Text, content.InlineKeyboard, inlineMessageId: messageID.inlineMessageId); } } } } }
public async Task Send(string apikey, Strings strings, long chatId, bool fromChannel = false) { FinishCreation(); ContentParts content = GetContent(strings, apikey, noApproximation: true); await Api.SendMessageAsync(apikey, chatId, content.Text, replyMarkup : (fromChannel ? content.InlineKeyboard : GenerateUserMarkup(strings, apikey))); }
internal async Task UpdateWithModeratePane(string apikey, Strings strings, int messageId, string text) { ContentParts content = GetContent(strings, apikey, noApproximation: true, moderatePane: true); await Api.EditMessageTextAsync(apikey, content.Text, content.InlineKeyboard, chatId, messageId); }
internal async Task UpdateWithOptionsPane(string apikey, Strings strings, int messageID, string text) { ContentParts content = GetContent(strings, apikey, noApproximation: true); await Api.EditMessageTextAsync(apikey, "<b>" + HtmlSpecialChars.Encode(strings.GetString(Strings.StringsList.optionsForPoll)) + "</b>\n\n" + content.Text, this.GenerateOptionsMarkup(strings), chatId, messageID); }
public void Send(string apikey, Strings strings, long chatId, int pagOffset) { ContentParts content = GetContent(strings, apikey, offset: pagOffset); Api.SendMessage(apikey, chatId, content.Text, replyMarkup: content.InlineKeyboard); }
public async Task <bool> RefreshInlineMessage(List <Instance> instances, long currentBotChatID, ContentParts content, ContentParts contentChannel, string currentInlineMessageID = null) { Instance currentInstance = instances.Find(x => x.chatID == currentBotChatID); bool inlineMessageEditSuccess = false; try { if (currentInlineMessageID != null) { MessageID currentMessageID = messageIds.Find(x => x.inlineMessageId == currentInlineMessageID); if (currentMessageID.messageIDInvalid) { throw new UpdateMessageIDInvalidException(); } else if (currentMessageID.botChatID == currentBotChatID) { ContentParts contentToSend = currentMessageID.channel ? contentChannel : content; if (RequestHandler.DoUpdate(instance: currentInstance, messageID: currentMessageID, messageTextLength: content.Text.Length, necessary: true)) { try { await Api.EditMessageTextAsync( currentInstance.apikey, contentToSend.Text, contentToSend.InlineKeyboard, inlineMessageID : currentMessageID.inlineMessageId ); inlineMessageEditSuccess = true; } catch (WJClubBotFrame.Exceptions.MessageIDInvalid) { currentMessageID.messageIDInvalid = true; } catch (WJClubBotFrame.Exceptions.TooManyRequests ex) { currentInstance.retryAt = DateTime.Now + TimeSpan.FromSeconds(ex.RetryAfter); } } else { if (RequestHandler.DoUpdate(instance: currentInstance, messageTextLength: content.Text.Length)) { throw new InstanceAtFullCapacity(); } else if (RequestHandler.DoUpdate(messageID: currentMessageID, messageTextLength: content.Text.Length)) { throw new MessageIDAtFullCapacity(); } else { //TODO This can only happen if the last request was on point one unit away and the clock has moved a tiny bit, maybe solve this differently throw new UnknownFullCapacity(); } } } else { throw new UpdateBotsDontMatchException(); } } } finally { //Todo figure this out /* * dBHandler.UpdateQueue.Add(new UpdateQueueObject { * poll = this, * priorityUpdates = inlineMessageEditSuccess ? new List<string> { currentInlineMessageID } : new List<string>(), * doneUpdates = new List<string>(), * important = false, * fromBotID = currentBotChatID, * });*/ } return(inlineMessageEditSuccess); }
public async Task Update(string apikey, Strings strings, long chatId, int messageID, int pagOffset, bool noApproximation) { ContentParts content = GetContent(strings, apikey, noApproximation, offset: pagOffset); await Api.EditMessageTextAsync(apikey, content.Text, content.InlineKeyboard, chatId, messageID); }
public void Update(string apikey, Strings strings, long chatId, int messageID, int pagOffset) { ContentParts content = GetContent(strings, apikey, offset: pagOffset); Api.EditMessageText(apikey, content.Text, content.InlineKeyboard, chatId, messageID); }
public static void Refresh(string apikey, Strings strings, Pointer pointer, long chatId, int messageId) { ContentParts content = prepare(strings, pointer); Api.EditMessageText(apikey, content.Text, content.InlineKeyboard, chatId, messageId); }
internal void UpdateWithModeratePane(string apikey, Strings strings, int messageId, string text) { ContentParts content = GetContent(strings, apikey, moderatePane: true); }
internal void UpdateWithOptionsPane(string apikey, Strings strings, int messageID, string text) { ContentParts content = GetContent(strings, apikey); Api.EditMessageText(apikey, "<b>" + HtmlSpecialChars.Encode(strings.GetString(Strings.stringsList.optionsForPoll)) + "</b>\n\n" + content.Text, this.GenerateOptionsMarkup(strings), chatId, messageID); }
public static void Send(string apikey, Strings strings, Pointer pointer) { ContentParts content = prepare(strings, pointer); Api.SendMessage(apikey, pointer.ChatId, content.Text, replyMarkup: content.InlineKeyboard); }
public async Task Send(string apikey, Strings strings, long chatId, int pagOffset) { ContentParts content = GetContent(strings, apikey, noApproximation: true, offset: pagOffset); await Api.SendMessageAsync(apikey, chatId, content.Text, replyMarkup : content.InlineKeyboard); }