Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Config config = JsonConvert.DeserializeObject <Config>(File.ReadAllText("Config.json"));

            Audio     = DiscordVoiceUtils.ReadFromFile(config.AudioPath);
            Nicknames = config.Nicknames;

            foreach (var inv in File.ReadAllLines(config.InvitesPath))
            {
                AvailableGuilds.Enqueue(new GuildInfo(inv));
            }

            StartAssignerAsync();

            foreach (var token in File.ReadAllLines(config.TokensPath))
            {
                try
                {
                    new BroadcastClient(token);
                }
                catch (InvalidTokenException ex)
                {
                    Console.WriteLine($"{ex.Token} is invalid!");
                }
            }

            Thread.Sleep(-1);
        }
Exemplo n.º 2
0
        public async void PopulateGuildsAndChannels()
        {
            try
            {
                // Set busy state and indeterminate progress
                IsEnabled = false;
                Progress  = -1;

                // Sanitize token
                TokenValue = TokenValue.Trim('"');

                // Create token
                var token = new AuthToken(
                    IsBotToken ? AuthTokenType.Bot : AuthTokenType.User,
                    TokenValue);

                // Save token
                _settingsService.LastToken = token;

                // Clear guild to channel map
                _guildChannelsMap.Clear();

                // Get DM channels
                {
                    var guild    = Guild.DirectMessages;
                    var channels = await _dataService.GetDirectMessageChannelsAsync(token);

                    // Order channels
                    channels = channels.OrderBy(c => c.Name).ToArray();

                    _guildChannelsMap[guild] = channels;
                }

                // Get guild channels
                {
                    var guilds = await _dataService.GetUserGuildsAsync(token);

                    foreach (var guild in guilds)
                    {
                        var channels = await _dataService.GetGuildChannelsAsync(token, guild.Id);

                        // Filter and order channels
                        channels = channels.Where(c => c.Type == ChannelType.GuildTextChat).OrderBy(c => c.Name).ToArray();

                        _guildChannelsMap[guild] = channels;
                    }
                }

                // Update available guilds
                AvailableGuilds = _guildChannelsMap.Keys.ToArray();

                // Select the first guild
                SelectedGuild = AvailableGuilds.FirstOrDefault();
            }
            catch (HttpErrorStatusCodeException ex) when(ex.StatusCode == HttpStatusCode.Unauthorized)
            {
                Notifications.Enqueue("Unauthorized – make sure the token is valid");
            }
            catch (HttpErrorStatusCodeException ex) when(ex.StatusCode == HttpStatusCode.Forbidden)
            {
                Notifications.Enqueue("Forbidden – account may be locked by 2FA");
            }
            finally
            {
                // Reset busy state and progress
                Progress  = 0;
                IsEnabled = true;
            }
        }
        public async void PopulateGuildsAndChannels()
        {
            // Create progress operation
            var operation = ProgressManager.CreateOperation();

            try
            {
                // Sanitize token
                TokenValue = TokenValue.Trim('"');

                // Create token
                var token = new AuthToken(
                    IsBotToken ? AuthTokenType.Bot : AuthTokenType.User,
                    TokenValue);

                // Save token
                _settingsService.LastToken = token;

                // Prepare available guild list
                var availableGuilds = new List <GuildViewModel>();

                // Get direct messages
                {
                    // Get fake guild
                    var guild = Guild.DirectMessages;

                    // Get channels
                    var channels = await _dataService.GetDirectMessageChannelsAsync(token);

                    // Create channel view models
                    var channelViewModels = new List <ChannelViewModel>();
                    foreach (var channel in channels)
                    {
                        // Get fake category
                        var category = channel.Type == ChannelType.DirectTextChat ? "Private" : "Group";

                        // Create channel view model
                        var channelViewModel = _viewModelFactory.CreateChannelViewModel(channel, category);

                        // Add to list
                        channelViewModels.Add(channelViewModel);
                    }

                    // Create guild view model
                    var guildViewModel = _viewModelFactory.CreateGuildViewModel(guild,
                                                                                channelViewModels.OrderBy(c => c.Category)
                                                                                .ThenBy(c => c.Model.Name)
                                                                                .ToArray());

                    // Add to list
                    availableGuilds.Add(guildViewModel);
                }

                // Get guilds
                var guilds = await _dataService.GetUserGuildsAsync(token);

                foreach (var guild in guilds)
                {
                    // Get channels
                    var channels = await _dataService.GetGuildChannelsAsync(token, guild.Id);

                    // Get category channels
                    var categoryChannels = channels.Where(c => c.Type == ChannelType.Category).ToArray();

                    // Get text channels
                    var textChannels = channels.Where(c => c.Type == ChannelType.GuildTextChat).ToArray();

                    // Create channel view models
                    var channelViewModels = new List <ChannelViewModel>();
                    foreach (var channel in textChannels)
                    {
                        // Get category
                        var category = categoryChannels.FirstOrDefault(c => c.Id == channel.ParentId)?.Name;

                        // Create channel view model
                        var channelViewModel = _viewModelFactory.CreateChannelViewModel(channel, category);

                        // Add to list
                        channelViewModels.Add(channelViewModel);
                    }

                    // Create guild view model
                    var guildViewModel = _viewModelFactory.CreateGuildViewModel(guild,
                                                                                channelViewModels.OrderBy(c => c.Category)
                                                                                .ThenBy(c => c.Model.Name)
                                                                                .ToArray());

                    // Add to list
                    availableGuilds.Add(guildViewModel);
                }

                // Update available guild list
                AvailableGuilds = availableGuilds;

                // Pre-select first guild
                SelectedGuild = AvailableGuilds.FirstOrDefault();
            }
            catch (HttpErrorStatusCodeException ex) when(ex.StatusCode == HttpStatusCode.Unauthorized)
            {
                Notifications.Enqueue("Unauthorized – make sure the token is valid");
            }
            catch (HttpErrorStatusCodeException ex) when(ex.StatusCode == HttpStatusCode.Forbidden)
            {
                Notifications.Enqueue("Forbidden – account may be locked by 2FA");
            }
            finally
            {
                // Dispose progress operation
                operation.Dispose();
            }
        }