Пример #1
0
        public async Task SendJoinMSG(SocketGuildUser user = null, SocketGuild guild = null, JoinSeverity j = JoinSeverity.Null)
        {
            if (!Ready)
            {
                return;
            }
            EmbedBuilder builder = new EmbedBuilder();

            switch (j)
            {
            case JoinSeverity.UserJoined:
                if (user.IsBot)
                {
                    return;
                }
                if (!(Convert.ToInt64(Ext._vMem._vMemory[user.Guild.Id][Settings.JoinRole])).Equals(0))
                {
                    try {
                        await user.AddRoleAsync(user.Guild.GetRole(Convert.ToUInt64(Ext._vMem._vMemory[user.Guild.Id][Settings.JoinRole])) as IRole);
                    }
                    catch (Exception e) {
                        await Log($"AddRoleAsync - {user.Guild.Id}", exception : e);
                    }
                }
                if (jSon.CheckPermChn(user.Guild, user.Guild.TextChannels.FirstOrDefault().Id, Commands.Welcome))
                {
                    builder.Description = EditMessage(Convert.ToString(Ext._vMem._vMemory[user.Guild.Id][Settings.Welcome]), user as IGuildUser, null, user.Guild as IGuild);
                    builder.WithThumbnailUrl(user.GetAvatarUrl(ImageFormat.Auto, (ushort)128));
                    builder.WithAuthor(new EmbedAuthorBuilder()
                    {
                        IconUrl = user.GetAvatarUrl(ImageFormat.Auto, (ushort)128), Name = $"{user.Username} joined {user.Guild.Name}!"
                    });
                }
                else
                {
                    return;
                }
                break;

            case JoinSeverity.UserLeft:
                if (!noSend.Contains(user.Id))
                {
                    if (jSon.CheckPermChn((user.Guild as IGuild), user.Guild.TextChannels.FirstOrDefault().Id, Commands.Leave))
                    {
                        builder.Description = EditMessage(Convert.ToString(Ext._vMem._vMemory[user.Guild.Id][Settings.Leave]), user as IGuildUser, null, user.Guild as IGuild);
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
                break;

            case JoinSeverity.BotJoined:
                await SendWelcomeMsg(guild);

                return;

            case JoinSeverity.BotLeft:
                JSON.DeleteJSON(guild as IGuild);
                builder.Description = string.Empty;
                break;

            case JoinSeverity.Null:
                builder.Description = $"**NULL**";
                break;

            default:
                builder.Description = $"**?NULL**";
                break;
            }
            builder.Color = user.Roles.MaxBy(x => x.Position).Color;
            //await (user.Guild.TextChannels.OrderBy(c => c.Id).FirstOrDefault() as IMessageChannel).SendMessageAsync(string.Empty, false, embed: builder.WithCurrentTimestamp().Build());
            if (Convert.ToUInt64(_vMem._vMemory[user.Guild.Id][Settings.WelcomeCHN]).Equals(0))
            {
                Modules.BaseCommands _bc = new Modules.BaseCommands();
                await _bc.SetWelcome_main(user.Guild.TextChannels.OrderBy(c => c.Id).FirstOrDefault() as ITextChannel);
            }
            else if (jSon.CheckPermChn(user.Guild, user.Guild.DefaultChannel.Id, Commands.Welcome) && user.Guild.CurrentUser.GuildPermissions.Administrator)
            {
                try
                {
                    await user.Guild.GetTextChannel((ulong)(long)_vMem._vMemory[user.Guild.Id][Settings.WelcomeCHN]).SendMessageAsync(string.Empty, false, embed: builder.WithCurrentTimestamp().Build());
                }
                catch (Exception e)
                {
                    await Log($"Send welcome / leave message! - {user.Guild.Id} - {user.Guild.Name}", exception : e);
                }
                //await (_client.GetChannel((ulong)(long)Ext._vMem._vMemory[user.Guild.Id][Modules.BaseCommands.Settings.WelcomeCHN]) as ITextChannel).SendMessageAsync(string.Empty, false, embed: builder.WithCurrentTimestamp().Build());
            }
        }