internal void OnMessageUpdated(object sender, MessageUpdatedEventArgs messageEvent) { if (MessageUpdated != null) { MessageUpdated(sender as IGeneratedAlgorithm, messageEvent); } }
public void GetInfoTest() { using (var fahClient = new FahClient(CreateClientFactory())) { Connect(fahClient); var buffer = fahClient.InternalBuffer; _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Do( new Func <byte[], int, int, int>(FillBufferWithClientInfoData1)).Repeat.Once(); _stream.Expect(x => x.DataAvailable).Return(true).Repeat.Once(); _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Do( new Func <byte[], int, int, int>(FillBufferWithClientInfoData2)).Repeat.Once(); _stream.Expect(x => x.DataAvailable).Return(true).Repeat.Once(); _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Do( new Func <byte[], int, int, int>(FillBufferWithClientInfoData3)).Repeat.Once(); MessageUpdatedEventArgs e = null; fahClient.MessageUpdated += (sender, args) => e = args; fahClient.SocketTimerElapsed(null, null); Assert.AreEqual(JsonMessageKey.Info, e.Key); Assert.AreEqual(typeof(Info), e.DataType); var info = fahClient.GetMessage <Info>(); Assert.IsNotNull(info); Assert.AreEqual(0, info.Errors.Count()); } _tcpClient.VerifyAllExpectations(); _stream.VerifyAllExpectations(); }
public void GetUnitDerivedCollectionTest() { using (var fahClient = new FahClient(CreateClientFactory())) { Connect(fahClient); var buffer = fahClient.InternalBuffer; _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Do( new Func <byte[], int, int, int>(FillBufferWithUnitsData)).Repeat.Once(); MessageUpdatedEventArgs e = null; fahClient.MessageUpdated += (sender, args) => e = args; fahClient.SocketTimerElapsed(null, null); Assert.AreEqual(JsonMessageKey.QueueInfo, e.Key); Assert.AreEqual(typeof(UnitCollection), e.DataType); var unitCollection = fahClient.GetMessage <UnitCollection, UnitDerived>(); Assert.IsNotNull(unitCollection); Assert.AreEqual(0, unitCollection.Errors.Count()); Assert.AreEqual(1, unitCollection.Count); Assert.AreEqual(1, unitCollection[0].Errors.Count()); } _tcpClient.VerifyAllExpectations(); _stream.VerifyAllExpectations(); }
public void GetLogUpdateTest() { using (var fahClient = new FahClient(CreateClientFactory())) { Connect(fahClient); var buffer = new byte[70 * 1024]; fahClient.InternalBuffer = buffer; _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Do( new Func <byte[], int, int, int>(FillBufferWithLogUpdateData)); MessageUpdatedEventArgs e = null; fahClient.MessageUpdated += (sender, args) => e = args; fahClient.SocketTimerElapsed(null, null); Assert.AreEqual(JsonMessageKey.LogUpdate, e.Key); Assert.AreEqual(typeof(LogUpdate), e.DataType); var logUpdate = fahClient.GetMessage <LogUpdate>(); Assert.IsNotNull(logUpdate); Assert.AreEqual('s', logUpdate.Value[0]); Assert.IsFalse(logUpdate.Value.EndsWith('\"')); } _tcpClient.VerifyAllExpectations(); _stream.VerifyAllExpectations(); }
private async void MsgUpdtd(object sender, MessageUpdatedEventArgs e) { try { if (e.Server == null || e.Channel.IsPrivate || e.User?.Id == NadekoBot.Client.CurrentUser.Id) { return; } var config = SpecificConfigurations.Default.Of(e.Server.Id); var chId = config.LogServerChannel; if (chId == null || e.Channel.Id == chId || config.LogserverIgnoreChannels.Contains(e.Channel.Id)) { return; } Channel ch; if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) { return; } await ch.SendMessage( $@"🕔`{prettyCurrentTime}` **Message** 📝 `#{e.Channel.Name}` 👤`{e.User?.ToString() ?? ("NULL")}` `Old:` {e.Before.Text.Unmention()} `New:` {e.After.Text.Unmention()}").ConfigureAwait(false); } catch { } }
public void UpdateTest1() { using (var messageCache = new MessageCache(CreateClientFactory())) { Connect(messageCache); var buffer = messageCache.InternalBuffer; _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Do( new Func <byte[], int, int, int>(ConnectionTests.FillBufferWithTestData)); MessageUpdatedEventArgs e = null; messageCache.MessageUpdated += (sender, args) => e = args; bool updateFinishedRaised = false; messageCache.UpdateFinished += delegate { updateFinishedRaised = true; }; messageCache.SocketTimerElapsed(null, null); Assert.AreEqual("units", e.Key); Assert.IsNull(e.DataType); Assert.IsTrue(updateFinishedRaised); Assert.IsNotNull(messageCache.GetJsonMessage(JsonMessageKey.QueueInfo)); } _tcpClient.VerifyAllExpectations(); _stream.VerifyAllExpectations(); }
public async ValueTask HandleMessageUpdated(object sender, MessageUpdatedEventArgs e) { foreach (var service in MessageUpdatedServices) { await ExecuteAsync((service, e) => service.OnMessageUpdated(e), service, e).ConfigureAwait(false); } }
private async void MessageUpdatedAsync(object sender, MessageUpdatedEventArgs e) { if (e.NewMessage.Author.Id == ulong.Parse(_config["UserIds:Paprika"])) { await HandlePaprikaMessage(e.NewMessage); } }
public async void RegexUpdatedEvent(object sender, MessageUpdatedEventArgs args) { try { await RemoveMessageByFilter(sender, args); } catch { } }
private void _client_MessageUpdated(object sender, MessageUpdatedEventArgs e) { string atachments = string.Empty; foreach (Discord.Message.Attachment a in e.After.Attachments) { atachments += " |attachment: " + a.Url; } this._dbcontroler.EditMessage(e.Before.Id, e.After.Text + atachments); }
/// <summary> /// Handles the engine message updated. /// </summary> /// <param name="algorithm">The algorithm.</param> /// <param name="messageEvent">The <see cref="MessageUpdatedEventArgs"/> instance containing the event data.</param> private void EngineMessageUpdated(IGeneratedAlgorithm algorithm, MessageUpdatedEventArgs messageEvent) { if (!this.MessageHistories.ContainsKey(messageEvent.MessageId)) { this.MessageHistories[messageEvent.MessageId] = new List <Bernoulli>(); } // Console.WriteLine(messageEvent); if (messageEvent.Message is Bernoulli) { this.MessageHistories[messageEvent.MessageId].Add((Bernoulli)messageEvent.Message); } }
public async void ObsceneUpdatedEvent(object sender, MessageUpdatedEventArgs args) { if (CheckEvent(args.Server)) { return; } try { await RemoveMessageByObscene(sender, args); } catch { } }
/// <summary> /// Message updated. /// </summary> /// <param name="algorithm">The algorithm.</param> /// <param name="messageEvent">The <see cref="MessageUpdatedEventArgs"/> instance containing the event data.</param> private void MessageUpdated(IGeneratedAlgorithm algorithm, MessageUpdatedEventArgs messageEvent) { if (!this.MessageHistories.ContainsKey(messageEvent.MessageId)) { this.MessageHistories[messageEvent.MessageId] = new List <Gaussian>(); } if (messageEvent.Message is Gaussian item) { this.MessageHistories[messageEvent.MessageId].Add(item); } // Console.WriteLine(messageEvent); }
private async void MsgUpdtd(object sender, MessageUpdatedEventArgs e) { try { if (e.Server == null || e.Channel.IsPrivate || e.User.Id == NadekoBot.Client.CurrentUser.Id) { return; } Channel ch; if (!logs.TryGetValue(e.Server, out ch) || e.Channel == ch) { return; } await ch.SendMessage($"`Type:` **Message updated** `Time:` **{DateTime.Now}** `Channel:` **{e.Channel.Name}**\n**BEFORE**: `{e.User}:` {e.Before.Text}\n---------------\n**AFTER**: `{e.User}:` {e.After.Text}"); } catch { } }
/// <summary> /// Used in generated code to fire an event when a message is updated (and optionally writes a trace as well). /// </summary> /// <typeparam name="T"></typeparam> /// <param name="input"></param> /// <param name="text"></param> /// <param name="onMessageUpdated"></param> /// <param name="doTraceAsWell"></param> /// <returns></returns> public static T FireEvent <T>([IsReturned] T input, string text, Action <MessageUpdatedEventArgs> onMessageUpdated, bool doTraceAsWell) { if (doTraceAsWell) { Trace(input, text); } var messageEvent = new MessageUpdatedEventArgs { MessageId = text, Message = input }; onMessageUpdated(messageEvent); return(input); }
public static async void HandleEdit(object client, MessageUpdatedEventArgs e) { // Don't handle own message or any message containing embeds that was *just* replied to if (e != null && e.Before != null && !e.Before.IsAuthor && ((e.Before.Embeds != null && e.Before.Embeds.Length == 0) || !IsMessageLastRepliedTo(e.Before.Channel.Id, e.Before.Id))) { if (LastHandledMessageOnChannel.ContainsKey(e.Before.Channel.Id)) { LastHandledMessageOnChannel.Remove(e.Before.Channel.Id); } bool calcDate = (DateTime.Now - e.Before.Timestamp).Minutes < Program.EditThreshold; string server = e.Before.Server == null ? "1-1" : e.Before.Server.Name; string user = e.Before.User == null ? "?" : e.Before.User.Name; string rawtext = e.Before.RawText ?? ""; Console.WriteLine(string.Format("[{0}][Edit] {1}: {2}", server, user, rawtext)); string reply = null; string[] words = rawtext.Split(' '); reply = await HandleCommands((DiscordClient)client, reply, words); if (reply == null) { reply = HandleEmotesAndConversions(reply, words); } if (!string.IsNullOrWhiteSpace(reply) && calcDate) { Message botRelation = GetExistingBotReplyOrNull(e.Before.Id); if (botRelation == null) { await SendReply(client, e.After, e.After.Channel.Id, e.After.Id, reply); } else if (botRelation != null) { try { await botRelation.Edit(reply); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } } } }
private async Task RemoveMessageByFilter(object sender, MessageUpdatedEventArgs args) { if (CheckEvent(args.Server)) { return; } if (!args.User.IsBot && CheckMessege(args.After.Text, (long)args.Server.Id)) { await args.After.Delete(); var botAnswer = await args.Channel.SendMessage(Strings.RemoveMessege); await Task.Delay(Constants.Delay); await botAnswer.Delete(); } }
public async Task HandleAsync(MessageUpdatedEventArgs args) { if (!(args.Channel is CachedTextChannel channel) || !args.OldMessage.HasValue || // TODO: What to do when message doesn't have value, other than ignore args.OldMessage.Value.Content?.Equals(args.NewMessage.Content ?? string.Empty) == true) // message content is identical { return; } using var ctx = new AdminDatabaseContext(_provider); var guild = await ctx.GetOrCreateGuildAsync(channel.Guild.Id); if (!(await ctx.GetLoggingChannelAsync(channel.Guild.Id, LogType.MessageUpdate) is { } logChannel)) { return; } var builder = new LocalEmbedBuilder() .WithErrorColor() .WithTitle(_localization.Localize(guild.Language, "logging_message_update", channel.Tag)) .WithDescription(args.NewMessage.Author.Format(false)) .AddField(_localization.Localize(guild.Language, "info_id"), args.NewMessage.Id) .WithTimestamp(DateTimeOffset.UtcNow); if (!string.IsNullOrWhiteSpace(args.OldMessage.Value.Content)) { builder.AddField(_localization.Localize(guild.Language, "logging_message_update_oldcontent"), args.OldMessage.Value.Content.TrimTo(1024, true)); } if (!string.IsNullOrWhiteSpace(args.NewMessage.Content)) { builder.AddField(_localization.Localize(guild.Language, "logging_message_update_newcontent"), args.NewMessage.Content.TrimTo(1024, true)); } await logChannel.SendMessageAsync(embed : builder.Build()); }
public static async Task HandleMessageEditedAsync(VerificationBot bot, MessageUpdatedEventArgs e) { // Sometimes fires for messages that haven't been edited // Unsure if this is a bug, or some other form of message update if (e.GuildId == null || e.OldMessage == null || e?.OldMessage?.Content == e?.NewMessage?.Content) { return; } LocalEmbedBuilder embed = null; foreach (ConfigChannel channel in bot.Config .GetOrAddGuild(e.GuildId.Value).Channels.Values .Where(c => c.ChangelogChannels.Contains(e.ChannelId))) { if (embed == null) { embed = new LocalEmbedBuilder() .WithTitle("Message edited") .AddField("Channel", $"<#{e.OldMessage.ChannelId}>") .AddField("Author", e.OldMessage.Author.Mention) .AddField("Old Content", e.OldMessage.Content.Length > 0 ? e.OldMessage.Content : "N/A") .AddField("Link", $"https://discord.com/channels/{e.GuildId.Value.RawValue}/{e.ChannelId.RawValue}/{e.MessageId.RawValue}"); } if (await bot.GetChannelAsync(channel.GuildId, channel.Id) is ITextChannel textChannel) { await textChannel.SendMessageAsync ( new LocalMessageBuilder() .WithEmbed(embed) .Build() ); } } }
public void GetHeartbeatTest() { using (var fahClient = new FahClient(CreateClientFactory())) { Connect(fahClient); var buffer = fahClient.InternalBuffer; _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Do( new Func <byte[], int, int, int>(FillBufferWithHeartbeatData)); MessageUpdatedEventArgs e = null; fahClient.MessageUpdated += (sender, args) => e = args; fahClient.SocketTimerElapsed(null, null); Assert.AreEqual(JsonMessageKey.Heartbeat, e.Key); Assert.AreEqual(typeof(Heartbeat), e.DataType); var heartbeat = fahClient.GetMessage <Heartbeat>(); Assert.IsNotNull(heartbeat); Assert.AreEqual(0, heartbeat.Errors.Count()); } _tcpClient.VerifyAllExpectations(); _stream.VerifyAllExpectations(); }
/// <summary> /// Discord message updated /// </summary> /// <param name="sender">object</param> /// <param name="e">MessageUpdatedEventArgs</param> private void MClient_MessageUpdated(object sender, MessageUpdatedEventArgs e) { mLogMessages.Write(Log.LogLevel.Text, $"{e.User.Name} @ {e.Channel.Name} updated: {e.After.Text}"); }
private Task OnMessageEdited(object sender, MessageUpdatedEventArgs e) => ChangelogService.HandleMessageEditedAsync(this, e);
public async void messageUpdated(object sender, MessageUpdatedEventArgs e) { if (e == null || e.Before == null || e.After == null || e.User == null || e.Channel == null || e.Server == null) { return; } if (MidnightBot.Client.CurrentUser.Id == e.User.Id) { return; } if (MidnightBot.Config.ListenChannels.Contains(e.Channel.Id)) { var uid = Convert.ToInt64(e.User.Id); LevelData ldm = DbHandler.Instance.FindOne <LevelData>(p => p.UserId == uid); if (ldm != null) { int xpToRemove = (e.Before.RawText.Length > 25 ? 25 : e.Before.RawText.Length); if ((ldm.TotalXP - xpToRemove) <= 0) { ldm.TotalXP = 0; } else { ldm.TotalXP -= xpToRemove; } //Calculate new level int copyOfTotalXP = ldm.TotalXP; int calculatedLevel = 1; while (copyOfTotalXP > 0) { int xpNeededForNextLevel = 5 * (calculatedLevel ^ 2) + 50 * calculatedLevel + 100; if (copyOfTotalXP > xpNeededForNextLevel) { calculatedLevel++; copyOfTotalXP -= xpNeededForNextLevel; } else { ldm.CurrentXP = copyOfTotalXP; break; } } ldm.Level = calculatedLevel; ldm.XPForNextLevel = 5 * (calculatedLevel ^ 2) + 50 * calculatedLevel + 100; //Add New Levels int xpToGet = (e.After.RawText.Length > 25 ? 25 : e.After.RawText.Length); ldm.CurrentXP += xpToGet; ldm.TotalXP += xpToGet; if (ldm.CurrentXP >= ldm.XPForNextLevel) { if (ldm.CurrentXP > ldm.XPForNextLevel) { ldm.CurrentXP = (ldm.XPForNextLevel - ldm.CurrentXP); } else { ldm.CurrentXP = 0; } ldm.Level += 1; ldm.XPForNextLevel = 5 * (ldm.Level ^ 2) + 50 * ldm.Level + 100; await e.Channel.SendMessage($"Herzlichen Glückwunsch { e.User.Mention }, du hast Level { ldm.Level } erreicht!"); } DbHandler.Instance.Save(ldm); } } }
protected internal virtual ValueTask OnMessageUpdated(MessageUpdatedEventArgs e) => default;
public static Channel getLogChannel(MessageUpdatedEventArgs msg) { var log = msg.Server.FindChannels(Strings.logChannel, ChannelType.Text).FirstOrDefault(); return(log); }
internal void OnMessageUpdated(object sender, MessageUpdatedEventArgs messageEvent) { MessageUpdated?.Invoke(sender as IGeneratedAlgorithm, messageEvent); }
public void Bot_MessageUpdated(object sender, MessageUpdatedEventArgs e) { }
private void FahClientMessageUpdated(object sender, MessageUpdatedEventArgs e) { JsonMessage jsonMessage = _fahClient.GetJsonMessage(e.Key); AppendToMessageDisplayTextBox(String.Empty); AppendToMessageDisplayTextBox(jsonMessage.ToString()); if (e.DataType == typeof(SlotCollection)) { var slotCollection = _fahClient.GetMessage<SlotCollection>(); foreach (var slot in slotCollection) { _fahClient.SendCommand("slot-options " + slot.Id + " client-type client-subtype cpu-usage machine-id max-packet-size core-priority next-unit-percentage max-units checkpoint pause-on-start gpu-index gpu-usage"); _fahClient.SendCommand("simulation-info " + slot.Id); } } }