Beispiel #1
0
        private async Task ChannelUpdated(DiscordClient sender, ChannelUpdateEventArgs e)
        {
            _newEntry = await GetNewEntryAsync();

            _entryBuilder = new DiscordEmbedBuilder();

            string commonType  = e.ChannelAfter.Type.ToRusCommon();
            string channelName = e.ChannelAfter.Name;


            var  entryType         = _newEntry?.ActionType;
            bool checkForSameEntry = false;

            switch (entryType)
            {
            case (AuditLogActionType.ChannelUpdate):
            {
                checkForSameEntry = true;        //Important because in second case we have defense by ow == null, and if any small updates happen don't wanna send same channel update entries
                var cuEntry = _newEntry as DiscordAuditLogChannelEntry;
                _entryBuilder = EmbedBuilderExtensions.CreateForAudit(cuEntry,
                                                                      $"Обновление параметров {commonType}",
                                                                      $"Обновлены параметры у {commonType} {channelName}");

                _entryBuilder.AddNamePropertyChange(cuEntry.NameChange);

                _entryBuilder.AddPropertyChange("Битрейт", cuEntry.BitrateChange);
                _entryBuilder.AddPropertyChange("NSFW", cuEntry.NsfwChange);
                _entryBuilder.AddPropertyChange("Слоумод", cuEntry.PerUserRateLimitChange);
                _entryBuilder.AddPropertyChange("Тема", cuEntry.TopicChange);
                break;
            }

            default:     // case if overwrite entry
            {
                var owsBefore = e.ChannelBefore.PermissionOverwrites;
                var owsAfter  = e.ChannelAfter.PermissionOverwrites;
                OverwriteUpdateInformation owUpdInfo = new OverwriteUpdateInformation(owsBefore, owsAfter);
                if (_newEntry != null)
                {
                    _entryBuilder = EmbedBuilderExtensions.CreateForAudit(_newEntry);
                    _entryBuilder.AddField("Изменённые оверврайты", string.Join("\n", owUpdInfo.Changes));
                }

                var ow = owUpdInfo.GetAffectedOverwrite();
                if (ow == null)
                {
                    return;                     //If we don't have overwriteupdates at all
                }
                _entryBuilder.SetTitle($"{owUpdInfo.Action} оверврайтов");

                string subj = ow.Type == OverwriteType.Role ?
                              "роли " + ow.GetRoleAsync().Result.Name :
                              "пользователя " + ow.GetMemberAsync().Result.Username;

                _entryBuilder.SetDescription($"{owUpdInfo.Action} оверврайтов для {subj} у {e.ChannelAfter.Type.ToRusCommon()} {channelName} ");
            }
            break;
            }
            await SendMessageToAuditAsync(checkForSameEntry, embed : _entryBuilder); //Don't set true on defense from same entry,
        }
Beispiel #2
0
 private Task Client_ChannelUpdated(ChannelUpdateEventArgs e)
 {
     e.Client.DebugLogger.LogMessage(LogLevel.Info, "BotApp", $"{e.ChannelBefore.Name} just updated",
                                     DateTime.Now);
     if (e.ChannelBefore.IsNSFW != e.ChannelAfter.IsNSFW)
     {
         e.Client.DebugLogger.LogMessage(LogLevel.Debug, "BotApp",
                                         $"{e.ChannelBefore.Name} is {(e.ChannelAfter.IsNSFW ? "now" : "no longer")} NSFW", DateTime.Now);
     }
     if (e.ChannelBefore.IsPrivate != e.ChannelAfter.IsPrivate)
     {
         e.Client.DebugLogger.LogMessage(LogLevel.Debug, "BotApp",
                                         $"{e.ChannelBefore.Name} is {(e.ChannelAfter.IsPrivate ? "now" : "no longer")} private",
                                         DateTime.Now);
     }
     if (e.ChannelBefore.Name != e.ChannelAfter.Name)
     {
         e.Client.DebugLogger.LogMessage(LogLevel.Debug, "BotApp",
                                         $"{e.ChannelBefore.Name} is now named {e.ChannelAfter.Name}", DateTime.Now);
     }
     if (e.ChannelBefore.Topic != e.ChannelAfter.Topic)
     {
         e.Client.DebugLogger.LogMessage(LogLevel.Debug, "BotApp",
                                         $"{e.ChannelBefore.Name}'s topic is now {e.ChannelAfter.Topic}", DateTime.Now);
     }
     return(Task.CompletedTask);
 }
Beispiel #3
0
 private async Task OnChannelUpdated(ChannelUpdateEventArgs e)
 {
     if (ChannelUpdated != null)
     {
         await ChannelUpdated(e);
     }
 }
Beispiel #4
0
        private static async Task Discord_ChannelUpdated(ChannelUpdateEventArgs e)
        {
#if DEBUG
            var ch = await DiscordClient.GetDefaultChannelAsync();

            await ch.SendMessageAsync("ChannelUpdated");
#endif
        }
Beispiel #5
0
        /// <summary>
        /// Processes a channel update and changes the displayed stream channel name if appropriate.
        /// </summary>
        /// <param name="e">The ChannelUpdateEventArgs event.</param>
        /// <returns>The task representing the method's execution state.</returns>
        private Task Client_ChannelUpdated(DiscordClient client, ChannelUpdateEventArgs e)
        {
            if (e.ChannelAfter.Id == this.ChannelId)
            {
                this.StreamChannelName = e.ChannelAfter.Name;
            }

            return(Task.CompletedTask);
        }
        private Task DiscordClient_ChannelUpdated(ChannelUpdateEventArgs e)
        {
            var channel = e.ChannelAfter;

            if (channel.Type == ChannelType.Text && channel.Name.Contains("broad") && !channels.Any(x => x.Id == channel.Id))
            {
                lock (channels)
                    channels.Add(channel);
            }
            return(Task.CompletedTask);
        }
Beispiel #7
0
 private async Task ChannelUpdated(DiscordClient c, ChannelUpdateEventArgs e)
 {
     Task.Run(async() =>
     {
         if (!e.ChannelBefore.IsPrivate)
         {
             await logService.GuildLogger(c, e.Guild, e, LogType.Guild).ConfigureAwait(true);
             this.logger.Information($"Channel '{e.ChannelAfter.Name}' ({e.ChannelAfter.Id}) has been updated on guild '{e.Guild.Name}' ({e.Guild.Id}).");
         }
     });
 }
Beispiel #8
0
        private void Config1Save_ButtonClicked(object sender, Form2.ConfigUpdateEventArgs e)
        {
            ChannelUpdateEventArgs args = new ChannelUpdateEventArgs(e.chNumber, e.partNumber, e.testType, e.testID, e.lowerTestLimit, e.upperTestLimit, e.limitexceeded, e.testResult);

            ChannelUpdated(this, args);

            int chNumber = Int32.Parse(e.chNumber);

            dutSample[chNumber] = new DUTSample(e.chNumber, e.partNumber, e.customer, e.testType, e.testID, e.lowerTestLimit, e.upperTestLimit, e.limitexceeded, e.testResult);
            dutAdapter.addItem(dutSample[chNumber]); // add to index 0..1..2
        }
Beispiel #9
0
        public static async Task OnChannelUpdate(ModCoreShard shard, ChannelUpdateEventArgs ea)
        {
            if (ea.Guild == null)
                return;

            using (var db = shard.Database.CreateContext())
            {
                var cfg = ea.Guild.GetGuildSettings(db);
                if (cfg == null || !cfg.RoleState.Enable)
                    return;
                var rs = cfg.RoleState;

                if (rs.IgnoredChannelIds.Contains(ea.ChannelAfter.Id))
                    return;

                var os = ea.ChannelAfter.PermissionOverwrites.Where(xo => xo.Type.ToString().ToLower() == "member").ToDictionary(xo => (long)xo.Id, xo => xo);
                var osids = os.Select(xo => xo.Key).ToArray();

                var chperms = db.RolestateOverrides.Where(xs => xs.GuildId == (long)ea.Guild.Id && xs.ChannelId == (long)ea.ChannelAfter.Id)
                    .ToDictionary(xs => xs.MemberId, xs => xs);
                var permids = chperms.Select(xo => xo.Key).ToArray();

                var del = permids.Except(osids);
                var add = osids.Except(permids);
                var mod = osids.Intersect(permids);

                if (del.Any())
                    db.RolestateOverrides.RemoveRange(del.Select(xid => chperms[xid]));

                if (add.Any())
                    await db.RolestateOverrides.AddRangeAsync(add.Select(xid => new DatabaseRolestateOverride
                    {
                        ChannelId = (long)ea.ChannelAfter.Id,
                        GuildId = (long)ea.Guild.Id,
                        MemberId = xid,
                        PermsAllow = (long)os[xid].Allowed,
                        PermsDeny = (long)os[xid].Denied
                    }));

                if (mod.Any())
                    foreach (var xid in mod)
                    {
                        chperms[xid].PermsAllow = (long)os[xid].Allowed;
                        chperms[xid].PermsDeny = (long)os[xid].Denied;

                        db.RolestateOverrides.Update(chperms[xid]);
                    }

                if (del.Any() || add.Any() || mod.Any())
                    await db.SaveChangesAsync();
            }
        }
Beispiel #10
0
        private void ChannelUpdateDetected(object sender, ChannelUpdateEventArgs args)
        {
            characterList.Dispatcher.Invoke(() =>
            {
                //var tempList = new List<string>();

                //foreach (var item in args.Channel.Players.Last().Character.Items)
                //{
                //    tempList.Add(item.InventoryId);
                //}

                characterList.ItemsSource = args.Channel.Players;
            });
        }
Beispiel #11
0
 private static void Mixer_StatusUpdate(object sender, ChannelUpdateEventArgs e)
 {
     if (e.Channel.Online == null)
     {
         return;
     }
     Print(DarkGray, $"{DateTime.Now.ToLongTimeString()} ");
     Print(Gray, "Channel is now ");
     if (e.Channel.Online == true)
     {
         Print(Green, "ONLINE\n");
     }
     else
     {
         Print(Red, "OFFLINE\n");
     }
 }
Beispiel #12
0
        internal static Task ChannelUpdated(DiscordClient _1, ChannelUpdateEventArgs e)
        {
            //TODO Permissions

            _ = Task.Run(async() =>
            {
                if (e.Guild.Id != 699555747591094344)
                {
                    return;
                }

                if (e.ChannelBefore.Id == 722905404354592900)
                {
                    return;
                }
                if (e.ChannelBefore.Name == e.ChannelAfter.Name &&
                    e.ChannelBefore.Parent.Name == e.ChannelAfter.Parent.Name &&
                    e.ChannelBefore.Topic == e.ChannelAfter.Topic &&
                    e.ChannelBefore.IsNSFW == e.ChannelAfter.IsNSFW &&
                    e.ChannelBefore.PerUserRateLimit == e.ChannelAfter.PerUserRateLimit)
                {
                    return;
                }
                DiscordEmbedBuilder embed = new DiscordEmbedBuilder()
                                            .WithTimestamp(DateTime.Now)
                                            .WithDescription($":information_source: The channel {e.ChannelAfter.Mention} ({e.ChannelAfter.Id}) was just updated")
                                            .AddField("Name", e.ChannelBefore.Name == e.ChannelAfter.Name ? "No change" : $"{e.ChannelBefore.Name} -> {e.ChannelAfter.Name}", true)
                                            .AddField("Category", e.ChannelBefore.Parent.Name == e.ChannelAfter.Parent.Name ? "No change" : $"{e.ChannelBefore.Parent.Name} -> {e.ChannelAfter.Parent.Name}", true)
                                            .AddField("Topic", e.ChannelBefore.Topic == e.ChannelAfter.Topic ? "No change" : $"{e.ChannelBefore.Topic} -> {e.ChannelAfter.Topic}", true)
                                            .AddField("NSFW", e.ChannelBefore.IsNSFW == e.ChannelAfter.IsNSFW ? "No change" : $"{e.ChannelBefore.IsNSFW} -> {e.ChannelAfter.IsNSFW}", true)
                                            .AddField("Slowmode (seconds)", e.ChannelBefore.PerUserRateLimit == e.ChannelAfter.PerUserRateLimit ? "No change" : $"{e.ChannelBefore.PerUserRateLimit} -> {e.ChannelAfter.PerUserRateLimit}", true)
                                            .WithColor(DiscordColor.Blurple);

                await DiscordObjectService.Instance.LogsChannel.SendMessageAsync(embed);
            });
            return(Task.CompletedTask);
        }
Beispiel #13
0
        private static async Task ChannelUpdate(BaseDiscordClient client, Embed embed, ChannelUpdateEventArgs channelUpdateEventArgs)
        {
            var before = channelUpdateEventArgs.ChannelBefore;
            var after  = channelUpdateEventArgs.ChannelAfter;

            if (!before.IsPrivate)
            {
                var nameChanged             = before.Name != after.Name;
                var topicChanged            = before.Topic != after.Topic;
                var parentChanged           = before.Parent != after.Parent;
                var isNsfwChanged           = before.IsNSFW != after.IsNSFW;
                var bitrateChanged          = before.Bitrate != after.Bitrate && after.Type == ChannelType.Voice;
                var userLimitChanged        = before.UserLimit != after.UserLimit;
                var perUserRateLimitChanged = before.PerUserRateLimit != after.PerUserRateLimit && after.Type == ChannelType.Text;
                var channelChanged          = nameChanged ||
                                              topicChanged ||
                                              parentChanged ||
                                              isNsfwChanged ||
                                              bitrateChanged ||
                                              userLimitChanged ||
                                              perUserRateLimitChanged;

                if (channelChanged)
                {
                    embed.Title = $"{DiscordEmoji.FromGuildEmote(client, EmojiLibrary.Update)} {after.Type.ToString()} channel updated";
                    var desciprtion = new StringBuilder()
                                      .AppendLine(!nameChanged
                            ? $"{Formatter.InlineCode(after.Name)} {after.Mention}"
                            : $"{Formatter.InlineCode(before.Name)} to {Formatter.InlineCode(after.Name)} {after.Mention}");

                    if (!string.IsNullOrWhiteSpace(after.Topic))
                    {
                        desciprtion.AppendLine(!topicChanged
                            ? $"Topic: {after.Topic}"
                            : $"Topic: {after.Topic}\nTopic old: {before.Topic}");
                    }

                    desciprtion.AppendLine($"Identity: {Formatter.InlineCode(after.Id.ToString())}")
                    .AppendLine(!parentChanged
                            ? $"Parent: {Formatter.InlineCode(after.Parent.Name)}"
                            : $"Parent: {Formatter.Underline(before.Parent.Name)} to {Formatter.InlineCode(after.Parent.Name)}")
                    .AppendLine(!isNsfwChanged
                            ? $"NSFW: {Formatter.InlineCode(after.IsNSFW.ToString())}"
                            : $"NSFW: {Formatter.InlineCode(before.IsNSFW.ToString())} to {Formatter.InlineCode(after.IsNSFW.ToString())}");

                    if (after.Type == ChannelType.Voice)
                    {
                        desciprtion.AppendLine(!bitrateChanged
                                ? $"Bitrate: {Formatter.InlineCode(after.Bitrate.ToString())}"
                                : $"Bitrate: {Formatter.InlineCode(before.Bitrate.ToString())} to {Formatter.InlineCode(after.Bitrate.ToString())}")
                        .AppendLine(!userLimitChanged
                                ? $"User Limit: {Formatter.InlineCode(after.UserLimitToString())}"
                                : $"User Limit: {Formatter.InlineCode(before.UserLimitToString())} : {Formatter.InlineCode(after.UserLimitToString())}");
                    }

                    if (after.Type == ChannelType.Text)
                    {
                        desciprtion.AppendLine(!perUserRateLimitChanged
                            ? $"Slowmode: {Formatter.InlineCode(after.PerUserRateLimitToString())}"
                            : $"Slowmode: {Formatter.InlineCode(before.PerUserRateLimitToString())} to {Formatter.InlineCode(after.PerUserRateLimitToString())}");
                    }

                    embed.Description = desciprtion.ToString();
                    embed.Color       = DiscordColor.CornflowerBlue;
                }
                else
                {
                    passInformation = false;
                }
            }
        }
Beispiel #14
0
 private Task ChannelUpdated(ChannelUpdateEventArgs e)
 {
     /* This would kill my bot */
     return(Task.CompletedTask);
 }
 public void OnUpdateReceived(ChannelUpdateEventArgs e)
 {
     EventHandler<ChannelUpdateEventArgs> handler = UpdateReceived;
     if (handler != null) handler(this, e);
 }
        public static async Task ChannelUpdateEventHandlerAsync(TheGodfatherShard shard, ChannelUpdateEventArgs e)
        {
            if (e.ChannelBefore.Position != e.ChannelAfter.Position)
            {
                return;
            }

            DiscordChannel logchn = shard.SharedData.GetLogChannelForGuild(shard.Client, e.Guild);

            if (logchn == null)
            {
                return;
            }

            if (await shard.DatabaseService.IsExemptedAsync(e.Guild.Id, e.ChannelAfter.Id, EntityType.Channel))
            {
                return;
            }

            DiscordEmbedBuilder  emb   = FormEmbedBuilder(EventOrigin.Channel, "Channel updated");
            DiscordAuditLogEntry entry = await e.Guild.GetFirstAuditLogEntryAsync(AuditLogActionType.ChannelUpdate);

            if (entry != null && entry is DiscordAuditLogChannelEntry centry)       // Regular update
            {
                emb.WithDescription(centry.Target.ToString());
                emb.AddField("User responsible", centry.UserResponsible?.Mention ?? _unknown, inline: true);
                if (centry.BitrateChange != null)
                {
                    emb.AddField("Bitrate changed to", centry.BitrateChange.After.ToString(), inline: true);
                }
                if (centry.NameChange != null)
                {
                    emb.AddField("Name changed to", centry.NameChange.After, inline: true);
                }
                if (centry.NsfwChange != null)
                {
                    emb.AddField("NSFW flag changed to", centry.NsfwChange.After.Value.ToString(), inline: true);
                }
                if (centry.OverwriteChange != null)
                {
                    emb.AddField("Permissions overwrites changed", $"{centry.OverwriteChange.After.Count} overwrites after changes");
                }
                if (centry.TopicChange != null)
                {
                    string ptopic = Formatter.BlockCode(Formatter.Sanitize(string.IsNullOrWhiteSpace(centry.TopicChange.Before) ? " " : centry.TopicChange.Before));
                    string ctopic = Formatter.BlockCode(Formatter.Sanitize(string.IsNullOrWhiteSpace(centry.TopicChange.After) ? " " : centry.TopicChange.After));
                    emb.AddField("Topic changed", $"From:{ptopic}\nTo:{ctopic}");
                }
                if (centry.TypeChange != null)
                {
                    emb.AddField("Type changed to", centry.TypeChange.After.Value.ToString());
                }
                if (!string.IsNullOrWhiteSpace(centry.Reason))
                {
                    emb.AddField("Reason", centry.Reason);
                }
                emb.WithFooter($"At {centry.CreationTimestamp.ToUniversalTime().ToString()} UTC", centry.UserResponsible.AvatarUrl);
            }
            else        // Overwrite update
            {
                AuditLogActionType type;
                if (e.ChannelBefore.PermissionOverwrites.Count > e.ChannelAfter.PermissionOverwrites.Count)
                {
                    type  = AuditLogActionType.OverwriteCreate;
                    entry = await e.Guild.GetFirstAuditLogEntryAsync(AuditLogActionType.OverwriteCreate);
                }
                else if (e.ChannelBefore.PermissionOverwrites.Count < e.ChannelAfter.PermissionOverwrites.Count)
                {
                    type  = AuditLogActionType.OverwriteDelete;
                    entry = await e.Guild.GetFirstAuditLogEntryAsync(AuditLogActionType.OverwriteDelete);
                }
                else
                {
                    if (e.ChannelBefore.PermissionOverwrites.Zip(e.ChannelAfter.PermissionOverwrites, (o1, o2) => o1.Allowed != o1.Allowed && o2.Denied != o2.Denied).Any())
                    {
                        type  = AuditLogActionType.OverwriteUpdate;
                        entry = await e.Guild.GetFirstAuditLogEntryAsync(AuditLogActionType.OverwriteUpdate);
                    }
                    else
                    {
                        type  = AuditLogActionType.ChannelUpdate;
                        entry = await e.Guild.GetFirstAuditLogEntryAsync(AuditLogActionType.ChannelUpdate);
                    }
                }

                if (entry != null && entry is DiscordAuditLogOverwriteEntry owentry)
                {
                    emb.WithDescription($"{owentry.Channel.ToString()} ({type})");
                    emb.AddField("User responsible", owentry.UserResponsible?.Mention ?? _unknown, inline: true);

                    DiscordUser member = null;
                    DiscordRole role   = null;

                    try {
                        bool isMemberUpdated = owentry.Target.Type.HasFlag(OverwriteType.Member);
                        if (isMemberUpdated)
                        {
                            member = await e.Client.GetUserAsync(owentry.Target.Id);
                        }
                        else
                        {
                            role = e.Guild.GetRole(owentry.Target.Id);
                        }
                        emb.AddField("Target", isMemberUpdated ? member.ToString() : role.ToString(), inline: true);
                        if (owentry.AllowChange != null)
                        {
                            emb.AddField("Allowed", $"{owentry.Target.Allowed.ToPermissionString() ?? _unknown}", inline: true);
                        }
                        if (owentry.DenyChange != null)
                        {
                            emb.AddField("Denied", $"{owentry.Target.Denied.ToPermissionString() ?? _unknown}", inline: true);
                        }
                    } catch {
                        emb.AddField("Target ID", owentry.Target.Id.ToString(), inline: true);
                    }

                    if (!string.IsNullOrWhiteSpace(owentry.Reason))
                    {
                        emb.AddField("Reason", owentry.Reason);
                    }
                    emb.WithFooter(owentry.CreationTimestamp.ToUtcTimestamp(), owentry.UserResponsible.AvatarUrl);
                }
                else
                {
                    return;
                }
            }

            await logchn.SendMessageAsync(embed : emb.Build());
        }
Beispiel #17
0
 public static void NewChannelUpdate(this IEventAggregator events, ChannelModel channel, ChannelUpdateEventArgs e)
 => events.NewUpdate(new ChannelUpdateModel(channel, e));
Beispiel #18
0
 public static void NewChannelUpdate(this IEventAggregator events, ChannelModel channel, ChannelUpdateEventArgs e)
     => events.NewUpdate(new ChannelUpdateModel(channel, e));
Beispiel #19
0
        private async Task OnDiscordChannelUpdated(ChannelUpdateEventArgs e)
        {
            Console.WriteLine($"[Discord] Channel update signal received! (guild: {e.Guild.Id})", Color.DodgerBlue);

            await PerformSnapshot(e.Guild);
        }
Beispiel #20
0
 private Task Event_ChannelUpdated(DiscordClient d, ChannelUpdateEventArgs e)
 {
     d.Logger.LogDebug(BotEventId, "Event_ChannelUpdated.");
     return(Task.CompletedTask);
 }