예제 #1
0
        public async Task SendWelcomeMsg(SocketGuild arg)
        {
            await Task.Delay(350);

            Modules.BaseCommands _bc = new Modules.BaseCommands();
            if (!DoesExistSettings(arg as IGuild))
            {
                CreateSettings(arg as IGuild);
            }
            if (!DoesExistJson(arg as IGuild))
            {
                CreateJson(arg as IGuild);
            }
            await Task.Delay(150);

            await _bc.SetWelcome_main(arg.TextChannels.OrderBy(c => c.Id).FirstOrDefault() as IMessageChannel);

            EmbedBuilder embed = new EmbedBuilder()
            {
                Author = new EmbedAuthorBuilder()
                {
                    Name    = $"{_client.CurrentUser.Username} joined {arg.Name}!",
                    IconUrl = _client.CurrentUser.GetAvatarUrl()
                },
                Title        = $"{_client.CurrentUser}",
                Description  = $"Bot made by: [Pat](http://daddybot.me/)\nBot made for: [M&D](https://discord.gg/D6qd4BE)\nBot created: {_client.CurrentUser.CreatedAt.Day}/{_client.CurrentUser.CreatedAt.Month}/{_client.CurrentUser.CreatedAt.Year} [D/M/Y]\nType .help for command info",
                ThumbnailUrl = _client.CurrentUser.GetAvatarUrl(),
                Color        = new Color((byte)(_ran.Next(255)), (byte)(_ran.Next(255)), (byte)(_ran.Next(255)))
            };

            await(arg.TextChannels.OrderBy(c => c.Id).FirstOrDefault() as IMessageChannel).SendMessageAsync(string.Empty, false, embed: embed.WithFooter(y => y.WithText(arg.Name)).WithCurrentTimestamp().Build());
            _vMem._run();
        }
예제 #2
0
 public object User_data(ulong id, User info)
 {
     Modules.BaseCommands _bc = new Modules.BaseCommands();
     try
     {
         if (!File.Exists($@"users/user_{id}.json"))
         {
             Dictionary<string, Dictionary<User, object>> userjson = new Dictionary<string, Dictionary<User, object>>
                 {
                     { "info", { User.Shekels, 100 }, { User.Bank, 50 }, { User.Storage, 1 } }}
예제 #3
0
파일: JSON.cs 프로젝트: Pat-1337/DiscordBot
 public bool CheckPermChn(IGuild guild, ulong id, Commands cmd)
 {
     Modules.BaseCommands _bc = new Modules.BaseCommands();
     Main.Program._client.Guilds.ToList().ForEach(async x => {
         if (!File.Exists($@"json/jayson_{x.Id}.json") && x.Id.Equals(guild.Id))
         {
             IEnumerable <IGuildChannel> channels = (await guild.GetChannelsAsync()).Where(y => y is SocketTextChannel).ToList().OrderBy(y => y.Position);
             Dictionary <ulong, Dictionary <Commands, bool> > perm = new Dictionary <ulong, Dictionary <Commands, bool> >();
             channels.ToList().ForEach(z => perm.Add(z.Id, _bc.inPerm));
             File.WriteAllText($@"json/jayson_{guild.Id}.json", JsonConvert.SerializeObject(perm, Formatting.Indented));
         }
     });
     if (JsonConvert.DeserializeObject <Dictionary <ulong, Dictionary <Commands, bool> > >(File.ReadAllText($@"json/jayson_{guild.Id}.json")).TryGetValue(id, out Dictionary <Commands, bool> dispatch))
     {
         if (dispatch.TryGetValue(cmd, out bool dispatch2))
         {
             return(dispatch2);
         }
         else
         {
             Dictionary <ulong, Dictionary <Commands, bool> > _parm = JsonConvert.DeserializeObject <Dictionary <ulong, Dictionary <Commands, bool> > >(File.ReadAllText($@"json/jayson_{guild.Id}.json"));
             _parm.TryAdd(id, _bc.inPerm);
             File.WriteAllText($@"json/jayson_{guild.Id}.json", JsonConvert.SerializeObject(_parm, Formatting.Indented));
             if (_parm[id].TryGetValue(cmd, out bool tf))
             {
                 return(tf);
             }
             else
             {
                 _parm[id].TryAdd(cmd, _bc.inPerm.Where(x => x.Key.Equals(cmd)).Select(x => x.Value).Single());
                 File.WriteAllText($@"json/jayson_{guild.Id}.json", JsonConvert.SerializeObject(_parm, Formatting.Indented));
                 return(_bc.inPerm.Where(x => x.Key.Equals(cmd)).Select(x => x.Value).Single());
             }
         }
     }
     else
     {
         Dictionary <ulong, Dictionary <Commands, bool> > _parm = JsonConvert.DeserializeObject <Dictionary <ulong, Dictionary <Commands, bool> > >(File.ReadAllText($@"json/jayson_{guild.Id}.json"));
         _parm.TryAdd(id, _bc.inPerm);
         File.WriteAllText($@"json/jayson_{guild.Id}.json", JsonConvert.SerializeObject(_parm, Formatting.Indented));
         if (_parm[id].TryGetValue(cmd, out bool tf))
         {
             return(tf);
         }
         else
         {
             _parm[id].TryAdd(cmd, _bc.inPerm.Where(x => x.Key.Equals(cmd)).Select(x => x.Value).Single());
             File.WriteAllText($@"json/jayson_{guild.Id}.json", JsonConvert.SerializeObject(_parm, Formatting.Indented));
             return(_bc.inPerm.Where(x => x.Key.Equals(cmd)).Select(x => x.Value).Single());
         }
     }
 }
예제 #4
0
파일: JSON.cs 프로젝트: Pat-1337/DiscordBot
 public object User_data(ulong id, User info)
 {
     Modules.BaseCommands _bc = new Modules.BaseCommands();
     try
     {
         if (!File.Exists($@"users/user_{id}.json"))
         {
             Dictionary <string, Dictionary <User, object> > userjson = new Dictionary <string, Dictionary <User, object> >
             {
                 { "info", _bc.inUser }
             };
             File.WriteAllText($@"users/user_{id}.json", JsonConvert.SerializeObject(userjson, Formatting.Indented));
         }
         Dictionary <string, Dictionary <User, object> > _json = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <User, object> > >(File.ReadAllText($@"users/user_{id}.json"));
         return(_json["info"][info]);
     }
     catch
     {
         Dictionary <string, Dictionary <User, object> > _json0 = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <User, object> > >(File.ReadAllText($@"users/user_{id}.json"));
         _json0["info"].TryAdd(info, _bc.inUser.Where(x => x.Key.Equals(info)).Select(x => x.Value).Single());
         File.WriteAllText($@"users/user_{id}.json", JsonConvert.SerializeObject(_json0, Formatting.Indented));
         return(_bc.inUser.Where(x => x.Key.Equals(info)).Select(x => x.Value).Single().ToString());
     }
 }
예제 #5
0
파일: JSON.cs 프로젝트: Pat-1337/DiscordBot
 public string Settings(IGuild guild, Settings stg)
 {
     Modules.BaseCommands _bc = new Modules.BaseCommands();
     try {
         Main.Program._client.Guilds.ToList().ForEach(x => {
             if (!File.Exists($@"Settings/settings_{x.Id}.json") && x.Id.Equals(guild.Id))
             {
                 Dictionary <string, Dictionary <Settings, object> > welcome = new Dictionary <string, Dictionary <Settings, object> >
                 {
                     { "Settings", _bc.inWelcome }
                 };
                 File.WriteAllText($@"Settings/settings_{guild.Id}.json", JsonConvert.SerializeObject(welcome, Formatting.Indented));
             }
         });
         Dictionary <string, Dictionary <Settings, object> > _json = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <Settings, object> > >(File.ReadAllText($@"Settings/settings_{guild.Id}.json"));
         return((string)_json["Settings"][stg]);
     }
     catch {
         Dictionary <string, Dictionary <Settings, object> > _json0 = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <Settings, object> > >(File.ReadAllText($@"Settings/settings_{guild.Id}.json"));
         _json0["Settings"].TryAdd(stg, _bc.inWelcome.Where(x => x.Key.Equals(stg)).Select(x => x.Value).Single());
         File.WriteAllText($@"Settings/settings_{guild.Id}.json", JsonConvert.SerializeObject(_json0, Formatting.Indented));
         return(_bc.inWelcome.Where(x => x.Key.Equals(stg)).Select(x => x.Value).Single().ToString());
     }
 }
예제 #6
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());
            }
        }