private async Task OnGuildMemberLeft(GuildMemberRemoveEventArgs e)
 {
     var guild = dataContainerReference[e.Guild].GuildInfo;
     //if (guild.BannedMembers.Any(member => member.ID == e.Member.Id)) return;
     await Task.CompletedTask;
     //Do something useful here as well.
 }
Exemple #2
0
        public async Task AddUserLeftEventAsync(GuildMemberRemoveEventArgs args)
        {
            UserEvent userEvent = new UserEvent()
            {
                UserId         = args.Member.Id,
                Username       = args.Member.Username,
                Nickname       = args.Member.Nickname,
                Discriminator  = args.Member.Discriminator,
                AvatarId       = args.Member.AvatarHash.ToString(),
                AccountCreated = args.Member.CreationTimestamp.UtcDateTime,
                Bot            = args.Member.IsBot,
                Event          = Event.Left,
                Timestamp      = DateTime.Now,
            };

            try
            {
                using IServiceScope scope = this.scopeFactory.CreateScope();
                using AnalyticsContext db = scope.ServiceProvider.GetRequiredService <AnalyticsContext>();
                db.UserEvents.Add(userEvent);
                await db.SaveChangesAsync();
            }
            catch (Exception e)
            {
                Log.Error(e, $"Failed to add new user event {userEvent.Username}#{userEvent.Discriminator} | {userEvent.UserId}");
                return;
            }
        }
Exemple #3
0
 public static async Task Say_Goodbye(DiscordClient Client, GuildMemberRemoveEventArgs e)
 {
     _ = Task.Run(async() =>
     {
         var WelcomeSettings = DB.DBLists.ServerWelcomeSettings.FirstOrDefault(w => w.Server_ID == e.Guild.Id);
         bool pendingcheck   = true;
         if (WelcomeSettings.HasScreening && e.Member.IsPending == true)
         {
             pendingcheck = false;
         }
         if (WelcomeSettings.Channel_ID != 0 && pendingcheck)
         {
             DiscordChannel WelcomeChannel = e.Guild.GetChannel(Convert.ToUInt64(WelcomeSettings.Channel_ID));
             if (WelcomeSettings.Goodbye_Message != null)
             {
                 string msg = WelcomeSettings.Goodbye_Message;
                 msg        = msg.Replace("$Username", $"{e.Member.Username}");
                 await WelcomeChannel.SendMessageAsync(msg);
             }
         }
         var ModMailEntry = DB.DBLists.ModMail.FirstOrDefault(w => w.User_ID == e.Member.Id && w.Server_ID == e.Guild.Id && w.IsActive);
         if (ModMailEntry != null)
         {
             await ModMail.CloseModMail(ModMailEntry, await Client.GetUserAsync(e.Member.Id), "Mod Mail entry closed due to user leaving", "**Mod Mail closed!\n----------------------------------------------------**");
         }
     });
     await Task.Delay(1);
 }
Exemple #4
0
        private static async Task BotProcess(DiscordClient Bot, GuildMemberRemoveEventArgs MemberObjects, GetLanguage Get_Language)
        {
            ulong Guild_ChannelID = Database.DatabaseMethods.GuildConfigMethods.LogChannelFind(MemberObjects.Guild.Id);

            if (Guild_ChannelID != 0)
            {
                DiscordChannel GuildLogChannel = MemberObjects.Guild.GetChannel(Guild_ChannelID);
                DiscordEmbed   LogChannelEmbed = new Discord​Embed​Builder()
                                                 .WithTitle(Get_Language.Language_Data.IsBot)
                                                 .WithDescription(
                    string.Format(
                        Get_Language.Language_Data.Bot_BanDescription,
                        MemberObjects.Member.Username + "#" + MemberObjects.Member.Discriminator,
                        MemberObjects.Member.Id
                        )
                    )
                                                 .WithColor(new DiscordColor(0x1971FF))
                                                 .WithTimestamp(DateTime.Now)
                                                 .WithFooter(
                    string.Format("{0} Bot", Bot.CurrentUser.Username)
                    )
                                                 .WithAuthor(Get_Language.Language_Data.BotRemoved);
                await GuildLogChannel.SendMessageAsync(LogChannelEmbed);
            }
            else
            {
                Log.Warning("Could not send from log channel");
            }

            Log.Debug($"{MemberObjects.Member.Username + "#" + MemberObjects.Member.Discriminator} is Bot");
            return;
        }
 public static async Task <string> ReplaceValues(string message, GuildMemberRemoveEventArgs e)
 {
     return(await ReplaceValues(message,
                                e.Member.Username,
                                e.Guild.Name,
                                e.Guild.MemberCount.ToString()));
 }
Exemple #6
0
 private async Task OnGuildMemberRemoved(GuildMemberRemoveEventArgs e)
 {
     if (GuildMemberRemoved != null)
     {
         await GuildMemberRemoved(e);
     }
 }
Exemple #7
0
        public async Task <Task> MemberRemoved(GuildMemberRemoveEventArgs e)
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Konsol.WriteLine($"--- {e.Member.Username} - {e.Guild.Name} Sunucusundan Ayrıldı ---");

            return(Task.Delay(0));
        }
Exemple #8
0
        private async Task GuildMemberRemoved(DiscordClient c, GuildMemberRemoveEventArgs e)
        {
            var kickEntry = await GetNewEntryAsync() as DiscordAuditLogKickEntry;

            if (kickEntry != null)
            {
                _entryBuilder = EmbedBuilderExtensions.CreateForAudit(kickEntry, "Кик", $"Пользователь {kickEntry.Target.Username} был кикнут");
                var reason = kickEntry.Reason.IsRelevant() ? kickEntry.Reason : "Не указана";
                _entryBuilder.AddField("Причина", reason);
                await SendMessageToAuditAsync(embed : _entryBuilder);
            }
            else
            {
                var banEntry = await GetNewEntryAsync() as DiscordAuditLogBanEntry;

                if (banEntry != null)
                {
                    return;
                }
                _entryBuilder = new DiscordEmbedBuilder();
                _entryBuilder.SetAuthor(e.Member);
                _entryBuilder.SetTitle("Пользователь покинул нас");
                _entryBuilder.SetDescription($"{e.Member.Mention} joined {e.Member.JoinedAt.LocalDateTime}");
                await SendMessageToAuditAsync(content : $"Пользователь {e.Member.Mention} покинул нас");
            }
        }
Exemple #9
0
        public static async Task OnGuildMemberRemoved(DiscordClient sender, GuildMemberRemoveEventArgs args)
        {
            var sanctions = await args.Guild.GetAuditLogsAsync(10, action_type : AuditLogActionType.Kick);

            var sanction = sanctions.OfType <DiscordAuditLogKickEntry>()
                           .FirstOrDefault(entry => entry.Target == args.Member);

            if (sanction == null)
            {
                return;
            }
            var responsible = sanction.UserResponsible;
            var reason      = sanction.Reason ?? "No reason provided.";
            var usrData     = DataContext.GetUserData(args.Guild.Id, args.Member.Id) ??
                              new UserData {
                Id = args.Member.Id, GuildId = args.Guild.Id
            };

            usrData.Sanctions ??= new List <Sanction>();
            usrData.Sanctions.Add(new Sanction
            {
                Type       = Sanction.SanctionType.Kick,
                PunisherId = responsible.Id,
                IssuedAt   = DateTimeOffset.Now,
                ExpiresAt  = DateTimeOffset.Now,
                Reason     = reason
            });
            DataContext.SaveUserData(usrData);
            sender.Logger.LogInformation(EventIds.Kick,
                                         "'{RUsername}#{RDiscriminator}' kicked '{PUsername}#{PDiscriminator}' for the following reason: {Reason}",
                                         responsible.Username, responsible.Discriminator, args.Member.Username, args.Member.Discriminator,
                                         reason);
        }
Exemple #10
0
 private async Task DBLogMemberLeft(DiscordClient dClient, GuildMemberRemoveEventArgs args)
 {
     if (IsSBG(args.Guild.Id))
     {
         await this.userEventService.AddUserLeftEventAsync(args);
     }
 }
Exemple #11
0
        public static async Task GuildMemberRemoved(GuildMemberRemoveEventArgs e, DiscordClient client)
        {
            var log = await client.Guilds.FirstOrDefault().Value.GetAuditLogsAsync(1, null);

            AuditLogActionType actionType = log.FirstOrDefault().ActionType;

            switch (actionType)
            {
            case AuditLogActionType.Ban:
            {
                await client.SendMessageAsync(e.Guild.Channels.Where(x => x.Name == "general").FirstOrDefault(),
                                              e.Member.Username + " kapott egy banhammert!", false);

                break;
            }

            case AuditLogActionType.Kick:
            {
                await client.SendMessageAsync(e.Guild.Channels.Where(x => x.Name == "general").FirstOrDefault(),
                                              e.Member.Username + " ki lett rúgva innen!", false);

                break;
            }
            }

            DiscordMessage msg = await client.SendMessageAsync(e.Guild.Channels.Where(x => x.Name == "general").FirstOrDefault(),
                                                               e.Member.Username + ", bukás!", false);
        }
    private Task ClientOnGuildMemberRemoved(DiscordClient sender, GuildMemberRemoveEventArgs e)
    {
        _ = Task.Factory.StartNew(async() =>
        {
            using var scope = this._provider.CreateScope();
            var db          = scope.ServiceProvider.GetRequiredService <DatabaseContext>();
            this._logger.LogDebug("User {Member} left guild {Guild}", e.Member, e.Guild);
            var user = await db.DiscordUsers.Include(u => u.Guilds).FirstOrDefaultAsync(u => u.DiscordUserId == e.Member.Id)
                       .ConfigureAwait(false);
            if (user == null)
            {
                this._logger.LogDebug("User {Member} that left wasn't saved in db", e.Member);
            }
            else
            {
                var guild = user.Guilds.FirstOrDefault(g => g.DiscordGuildId == e.Guild.Id);
                if (guild == null)
                {
                    this._logger.LogDebug("User {Member} that left guild {Guild} didn't have posting updates in it", e.Member, e.Guild);
                    return;
                }

                user.Guilds.Remove(guild);
                db.Update(user);
                await db.SaveChangesAndThrowOnNoneAsync().ConfigureAwait(false);
            }
        }, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Current).ContinueWith(
            task => this._logger.LogError(task.Exception, "Task on removing left member from the guild failed due to unknown reason"),
            CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.Current);
        return(Task.CompletedTask);
    }
Exemple #13
0
 public static async Task OnMemberRemove(GuildMemberRemoveEventArgs e)
 {
     if (Game.Players.ContainsKey(e.Member))
     {
         await Game.AddToPlayersToKick(e.Member);
     }
 }
Exemple #14
0
 private async Task GuildMemberRemoved(DiscordClient c, GuildMemberRemoveEventArgs e)
 {
     Task.Run(async() =>
     {
         await logService.GuildLogger(c, e.Guild, e, LogType.JoinedLeft).ConfigureAwait(true);
         this.logger.Information($"Member '{e.Member.GetUsertag()}' ({e.Member.Id}) has left the guild '{e.Guild.Name}' ({e.Guild.Id}).");
     });
 }
Exemple #15
0
        public static async Task OnMemberLeave(ModCoreShard shard, GuildMemberRemoveEventArgs ea)
        {
            using (var db = shard.Database.CreateContext())
            {
                var cfg = ea.Guild.GetGuildSettings(db);
                if (cfg == null || !cfg.RoleState.Enable)
                {
                    return;
                }
                var rs = cfg.RoleState;

                if (ea.Member.Roles.Any()) // no roles or cache miss, but at this point little can be done about it
                {
                    var rsx   = rs.IgnoredRoleIds;
                    var roles = ea.Member.Roles.Select(xr => xr.Id).Except(rsx).Select(xul => (long)xul);

                    var state = db.RolestateRoles.SingleOrDefault(xs => xs.GuildId == (long)ea.Guild.Id && xs.MemberId == (long)ea.Member.Id);
                    if (state == null) // no rolestate, create it
                    {
                        state = new DatabaseRolestateRoles
                        {
                            GuildId  = (long)ea.Guild.Id,
                            MemberId = (long)ea.Member.Id,
                            RoleIds  = roles.ToArray()
                        };
                        await db.RolestateRoles.AddAsync(state);
                    }
                    else // rolestate exists, update it
                    {
                        state.RoleIds = roles.ToArray();
                        db.RolestateRoles.Update(state);
                    }
                }

                var nickstate = db.RolestateNicks.SingleOrDefault(xs => xs.GuildId == (long)ea.Guild.Id && xs.MemberId == (long)ea.Member.Id);
                shard.Client.Logger.Log(LogLevel.Debug, "ModCore", $"Do nickname shites: {ea.Member.Nickname}", System.DateTime.Now);
                if (nickstate == null) // no nickstate, create it
                {
                    shard.Client.Logger.Log(LogLevel.Debug, "ModCore", "Create nickname shites", System.DateTime.Now);
                    nickstate = new DatabaseRolestateNick
                    {
                        GuildId  = (long)ea.Guild.Id,
                        MemberId = (long)ea.Member.Id,
                        Nickname = ea.Member.Nickname
                    };
                    await db.RolestateNicks.AddAsync(nickstate);
                }
                else // nickstate exists, update it
                {
                    shard.Client.Logger.Log(LogLevel.Debug, "ModCore", "Update nickname shites", System.DateTime.Now);
                    nickstate.Nickname = ea.Member.Nickname;
                    db.RolestateNicks.Update(nickstate);
                }

                // at this point, channel overrides do not exist
                await db.SaveChangesAsync();
            }
        }
Exemple #16
0
 public Task Bot_XedddBoiLeave(GuildMemberRemoveEventArgs e) //sends a message to owo if someone leaves the server
 {
     if (e.Guild.Id == 373635826703400960)
     {
         string leaver = e.Member.DisplayName + " (" + e.Member.Nickname + ") " + "left uwu";
         y.sendToChannel(391872124840574986, leaver); //the "e" does not provide a method to send stuff to another channel so thats the reason the method in form1 exists
     }
     return(Task.CompletedTask);
 }
Exemple #17
0
        //Announce users leaving the guild if enabled
        private async Task UserLeaveGuild(DiscordClient client, GuildMemberRemoveEventArgs e)
        {
            if (e.Member.IsCurrent)
            {
                return;
            }

            var GuildSettings = await this.Config.FindGuildSettings(e.Guild);

            DiscordChannel channel;

            //Check notification settings
            switch (GuildSettings.NotificationChannel)
            {
            case 0:
                return;

            case 1:
                channel = e.Guild.GetDefaultChannel();
                break;

            default:
                channel = e.Guild.GetChannel(GuildSettings.NotificationChannel);
                break;
            }
            if (channel == null)
            {
                return;
            }

            //Check if the user was banned
            DiscordBan UserBan = await e.Guild.GetBanAsync(e.Member);

            if (UserBan != null)
            {
                await channel.SendMessageAsync($"{e.Member.Mention} ({e.Member.Username}#{e.Member.Discriminator}) was banned from the guild with the reason `{UserBan.Reason}`");

                return;
            }

            //Check if the user was kicked
            //The only way to determine this is through the audit logs which can make this inconsistent
            var L = await e.Guild.GetAuditLogsAsync(1, action_type : AuditLogActionType.Kick);

            DiscordAuditLogKickEntry LastKick = (DiscordAuditLogKickEntry)L.FirstOrDefault();

            if (LastKick != null && LastKick.Target == e.Member)
            {
                await channel.SendMessageAsync($"{e.Member.Mention} ({e.Member.Username}#{e.Member.Discriminator}) was kicked from the guild with the reason `{LastKick.Reason}`");

                return;
            }

            //The user left on their own
            await channel.SendMessageAsync($"{e.Member.Mention} ({e.Member.Username}#{e.Member.Discriminator}) left the guild.");
        }
Exemple #18
0
        public async Task Bot_XedddBoiLeave(DiscordClient c, GuildMemberRemoveEventArgs e)
        {
            if (e.Guild.Id == 373635826703400960)
            {
                string leaver = e.Member.DisplayName + " (" + e.Member.Nickname + ") " + "left uwu";
                var    chn    = await bot.ShardClients.First(x => x.Value.Guilds.Any(y => y.Value.Id == 373635826703400960)).Value.GetChannelAsync(391872124840574986);

                await chn.SendMessageAsync(leaver);
            }
        }
Exemple #19
0
        private async Task OnGuildMemberRemoved(GuildMemberRemoveEventArgs e)
        {
            if (e.Member.IsBot)
            {
                return;
            }

            var userservice = (IUserService)_serviceProvider.GetService(typeof(IUserService));
            await userservice.DeleteUser(e.Guild.Id, e.Member.Id);
        }
Exemple #20
0
        // Why do you have these if you aren't going to use them?
        //async Task Client_MessageDeleted(MessageDeleteEventArgs e)
        //{
        //    try
        //    {

        //    }
        //    catch (Exception ex)
        //    {
        //        Console.WriteLine(ex.Message);
        //    }
        //}

        //async Task Client_BanRemoved(GuildBanRemoveEventArgs e)
        //{
        //    try
        //    {

        //    }
        //    catch(Exception ex)
        //    {
        //        Console.WriteLine(ex.Message);
        //    }
        //}

        async Task Client_MemberLeave(GuildMemberRemoveEventArgs e)
        {
            try
            {
                await e.Guild.GetChannel(691036573713563758).SendMessageAsync("A person has left. Goodbye" + e.Member.Mention + "!").Result.CreateReactionAsync(DiscordEmoji.FromUnicode("👋"));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemple #21
0
        public async Task <bool> HandleMemberLeaveAsync(GuildMemberRemoveEventArgs e, AntiInstantLeaveSettings settings)
        {
            if (!this.guildNewMembers.ContainsKey(e.Guild.Id) || !this.guildNewMembers[e.Guild.Id].Contains(e.Member))
            {
                return(false);
            }

            await this.PunishMemberAsync(e.Guild, e.Member, PunishmentActionType.PermanentBan);

            return(true);
        }
Exemple #22
0
 private async Task OnUserLeft(GuildMemberRemoveEventArgs args)
 {
     await _bus.SendAsync(new UserActionMessage
     {
         UserAction    = UserAction.Left,
         Id            = args.Member.Id,
         GuildId       = args.Guild.Id,
         Username      = args.Member.Username,
         Discriminator = args.Member.Discriminator
     });
 }
Exemple #23
0
        private async Task DiscordOnGuildMemberRemoved(DiscordClient sender, GuildMemberRemoveEventArgs e)
        {
            var guild   = sender.Guilds.First(x => x.Value.Name.ToLower().Contains("Devry")).Value;
            var channel = guild.Channels.First(x => x.Value.Name.ToLower().Equals("user-activity")).Value;

            DiscordEmbedBuilder builder = new DiscordEmbedBuilder()
                                          .WithAuthor("Hall Monitor")
                                          .WithDescription($"{e.Member.DisplayName} has left the building.");

            await channel.SendMessageAsync(embed : builder.Build());
        }
Exemple #24
0
 private Task OnGuildMemberRemoved(GuildMemberRemoveEventArgs e)
 {
     foreach (DiscordRole role in e.Member.Roles)
     {
         if (Config.trackedRoles.Contains(role.Id))
         {
             this.discordClient.DebugLogger.LogMessage(LogLevel.Info, Config.APPLICATION_NAME, e.Member.DisplayName + " (" + e.Member.Id + ") left the server with tracked role '" + role.Name + "'.", DateTime.UtcNow);
             Database.TryAddRole(e.Member.Id, role.Id);
         }
     }
     return(Task.CompletedTask);
 }
Exemple #25
0
        public static async Task SendLeaveMessageAsync(GuildMemberlogs g, GuildMemberRemoveEventArgs e)
        {
            if (!(g.MemberlogChannel is null))
            {
                string?msg = null;
                if (!(g.LeaveMessage?.Message is null))
                {
                    msg = await ReplaceValues(g.LeaveMessage.Message, e);
                }

                await SendLeaveMessageAsync(g, msg, e.Member.Username, e.Member?.AvatarUrl ?? "");
            }
        }
Exemple #26
0
        private Task Client_GuildMemberRemoved(GuildMemberRemoveEventArgs e)
        {
            try
            {
                Stats.Remove(e.Member.Id);

                return(Task.CompletedTask);
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
                throw;
            }
        }
Exemple #27
0
        private static Task Client_GuildMemberRemoved(GuildMemberRemoveEventArgs e)
        {
            //644283897609322497
            DiscordEmbedBuilder embed = new DiscordEmbedBuilder
            {
                Title = $"{e.Member.Username} left our server {e.Member.JoinedAt.ToString("hh:mm:ss")}",
                Color = DiscordColor.Azure
            };
            var channel = e.Guild.GetChannel(644283897609322497);

            channel.SendMessageAsync(embed: embed);

            return(Task.CompletedTask);
        }
Exemple #28
0
    private Task Client_GuildMemberRemoved(GuildMemberRemoveEventArgs e)
    {
        if (!MainThreadQueue.Instance.IsMain())
        {
            MainThreadQueue.Instance.Queue(() => Client_GuildMemberRemoved(e));
            return(Task.CompletedTask);
        }

        if (e.Guild == Guild && Members.Contains(e.Member))
        {
            Members.Remove(e.Member);
        }

        return(Task.CompletedTask);
    }
Exemple #29
0
        private async Task Client_GuildMemberRemoved(GuildMemberRemoveEventArgs e)
        {
            _logger.Trace($"FilterBot::Client_GuildMemberRemoved [Guild={e.Guild.Name}, Username={e.Member.Username}]");

            if (_config.NotifyMemberLeft)
            {
                var channel = await _client.GetChannel(_config.CommandsChannelId);

                if (channel == null)
                {
                    _logger.Error($"Failed to find channel with id {_config.CommandsChannelId}.");
                    return;
                }
                await channel.SendMessageAsync($"Sorry to see you go {e.Member.Mention}, hope to see you back soon!");
            }
        }
Exemple #30
0
        public static async Task GuildMemberRemoved(GuildMemberRemoveEventArgs args)
        {
            DiscordEmbedBuilder embed        = new DiscordEmbedBuilder();
            DiscordChannel      leaveChannel = args.Guild.GetChannelByName("join-leave");
            await leaveChannel.TriggerTypingAsync().ConfigureAwait(false);

            embed.Title       = "Member Left";
            embed.Description = $"{args.Member.Mention} has left. Goodbye";
            embed.Footer      = new DiscordEmbedBuilder.EmbedFooter()
            {
                Text    = args.Member.Username,
                IconUrl = args.Member.AvatarUrl
            };
            embed.Color = ColorUtils.GetRandomColor();
            await leaveChannel.SendMessageAsync(embed : embed).ConfigureAwait(false);
        }