Exemplo n.º 1
0
        public async Task RequestAuth()
        {
            try
            {
                var headers = new Dictionary <string, string>
                {
                    { "grant_type", "client_credentials" },
                    { "client_id", clientId },
                    { "client_secret", clientSecret },
                };

                using (var http = new HttpClient())
                {
                    //http.AddFakeHeaders();
                    http.DefaultRequestHeaders.Clear();
                    var formContent = new FormUrlEncodedContent(headers);
                    var response    = await http.PostAsync("https://anilist.co/api/auth/access_token", formContent).ConfigureAwait(false);

                    var stringContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    anilistToken = JObject.Parse(stringContent)["access_token"].ToString();
                }
                timeToUpdate = Environment.TickCount + 1700000;
                Console.WriteLine("ANILIST AUTHENTICATION SUCCESSFULL");
                await SentryService.SendMessage("ANILIST AUTHENTICATION **SUCCESSFULL**");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                await SentryService.SendMessage("ANILIST AUTHENTICATION **FAILED**");

                await SentryService.SendError(e);
            }
        }
Exemplo n.º 2
0
        public async Task <bool> onlyCheck(IUser user, IGuild guild, SocketCommandContext context = null, string otherContext = "No string")
        {
            try
            {
                if (userLimiterDict.ContainsKey(user.Id))
                {
                    userRate userStruct = new userRate();
                    userLimiterDict.TryGetValue(user.Id, out userStruct);
                    //CHECK TIME
                    if (Environment.TickCount < userStruct.timeBetween)
                    {
                        if (userStruct.counter >= 4)
                        {
                            //ratelimit
                            if (!userStruct.messageSent)
                            {
                                userStruct.timeBetween = Environment.TickCount + timeToAdd;
                                await(await user.GetOrCreateDMChannelAsync()).SendMessageAsync(
                                    "**You have been ratelimited for 20 seconds. Please do not spam commands! If you continue doing so your lockout will increase in time!**\n" +
                                    "If this was by mistake and you did not spam. join https://discord.gg/Pah4yj5 and @ me");
                                userStruct.timeBetween += punishTime;
                                userStruct.messageSent  = true;
                                await SentryService.SendMessage($"Rate limit occured:\n" +
                                                                $"User: {user.Username}#{user.Discriminator} \t{user.Id}\n" +
                                                                $"Guild: {guild.Name} \t {guild.Id}\n" +
                                                                $"Message: {(context == null ? otherContext : context.Message.Content)}");
                            }
                            userStruct.timeBetween += timeToAdd;
                            userLimiterDict.TryUpdate(user.Id, userStruct);
                            return(true);
                        }
                    }
                }

                return(false);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                if (context != null)
                {
                    await SentryService.SendError(e, context);
                }
                else
                {
                    await SentryService.SendError(e);
                }
            }
            return(false);
        }
Exemplo n.º 3
0
        public async Task AddRoleToList(SocketCommandContext Context, string roleName)
        {
            //Sora = 270931284489011202
            //Sora test = 276304865934704642
            try
            {
                var sora = Context.Guild.GetUser(270931284489011202);
                var role = Context.Guild.Roles.Where(x => x.Name == roleName).FirstOrDefault();
                //var soraRole = Context.Guild.Roles.Where(x => x.Name == "Sora").FirstOrDefault();
                var soraRole = sora.Roles.OrderByDescending(r => r.Position).FirstOrDefault();
                if (role == null)
                {
                    await Context.Channel.SendMessageAsync(":no_entry_sign: Couldn't find specified role!");

                    return;
                }
                if (soraRole == null)
                {
                    await Context.Channel.SendMessageAsync(
                        ":no_entry_sign: Couldn't find my own role! I apparently do not own any roles... Pls report this if it ever happens");

                    await SentryService.SendMessage(
                        $"Couldn't find Soras role? ;_; in {Context.Guild.Name} ({Context.Guild.Id})");

                    return;
                }
                if (soraRole.Position < role.Position)
                {
                    await Context.Channel.SendMessageAsync(
                        ":no_entry_sign: Can't assign Roles that are above me in the role hirachy! **If this is NOT true, open the role hirachy and move any role up once and then back to its initial position! This will update all role positions!**");

                    return;
                }
                if (!sora.GuildPermissions.Has(GuildPermission.ManageRoles))
                {
                    await Context.Channel.SendMessageAsync(
                        ":no_entry_sign: Sora needs Manage Roles permissions to add roles!");

                    return;
                }
                Console.WriteLine($"{soraRole.Position} : {role.Position}");

                if (_availableRoles.ContainsKey(Context.Guild.Id))
                {
                    List <ulong> roleIDs = new List <ulong>();
                    _availableRoles.TryGetValue(Context.Guild.Id, out roleIDs);
                    if (roleIDs.Contains(role.Id))
                    {
                        await Context.Channel.SendMessageAsync(":no_entry_sign: This role already is self-assignable");

                        return;
                    }
                    roleIDs.Add(role.Id);
                    _availableRoles.TryUpdate(Context.Guild.Id, roleIDs);
                }
                else
                {
                    List <ulong> roleIDs = new List <ulong>();
                    roleIDs.Add(role.Id);
                    _availableRoles.TryAdd(Context.Guild.Id, roleIDs);
                }
                SaveDatabase();

                await Context.Channel.SendMessageAsync($":white_check_mark: Successfully added Role `{role.Name}`");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                await Context.Channel.SendMessageAsync(
                    $":no_entry_sign: Failed to add role. I'm probably missing the perms!");

                await SentryService.SendError(e, Context);
            }
        }