Exemplo n.º 1
0
        private async Task JoinedGuildHandler(SocketGuild guild)
        {
            DiscordServer saved = _main.ServerList.FirstOrDefault(x => x.ServerId == guild.Id);

            if (saved != null)
            {
                saved.Active = true;
            }
            else
            {
                DiscordServer newServer = new DiscordServer()
                {
                    Active       = true,
                    ServerName   = guild.Name,
                    ServerId     = guild.Id,
                    Prefix       = PrefixChar.None,
                    ServerJoined = DateTime.Now.ToString()
                };
                App.Current.Dispatcher.Invoke((Action) delegate
                {
                    _main.ServerList.Add(newServer);
                });
            }
            BotFrame.SaveFile("servers");
            _main.ServerList.Clear();
            BotFrame.LoadFile("servers");
        }
Exemplo n.º 2
0
        private void ReactionLocksEdit_Click(object sender, RoutedEventArgs e)
        {
            if (reactionListBox.SelectedIndex == -1)
            {
                return;
            }
            ReactionLockEditor rl = new ReactionLockEditor();

            rl.Owner  = this;
            rl._lock  = _server.ReactionLockList[reactionListBox.SelectedIndex];
            rl.Title  = $"Edit lock {rl._lock.MessageId}";
            IsEnabled = false;
            rl.ShowDialog();
            IsEnabled = true;
            if (rl.DialogResult.HasValue && rl.DialogResult.Value)
            {
                rl._lock.ChannelId = ulong.Parse(rl.channelBox.Text);
                rl._lock.MessageId = ulong.Parse(rl.messageBox.Text);
                rl._lock.Emote     = rl.emoteBox.Text;
                rl._lock.GiveRole  = ulong.Parse(rl.giveRoleBox.Text);
                rl._lock.TakeRole  = ulong.Parse(rl.takeRoleBox.Text);
                UpdateView("reactionlock");
                BotFrame.SaveFile("servers");
            }
        }
Exemplo n.º 3
0
        //ReactionLocks
        private void ReactionLocksAdd_Click(object sender, RoutedEventArgs e)
        {
            ReactionLockEditor rl = new ReactionLockEditor();

            rl.Owner  = this;
            rl.Title  = "New Reaction Lock";
            IsEnabled = false;
            rl.ShowDialog();
            IsEnabled = true;
            if (rl.DialogResult.HasValue && rl.DialogResult.Value)
            {
                if (_server.ReactionLockList.FirstOrDefault(x => x.ChannelId == ulong.Parse(rl.channelBox.Text) && x.MessageId == ulong.Parse(rl.messageBox.Text)) != null)
                {
                    MessageBox.Show("You are trying to add a reaction lock that already has an entry, please select the reaction lock entry and edit it instead!", "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                ReactionLock newLock = new ReactionLock()
                {
                    ChannelId = ulong.Parse(rl.channelBox.Text),
                    MessageId = ulong.Parse(rl.messageBox.Text),
                    Emote     = rl.emoteBox.Text,
                    GiveRole  = ulong.Parse(rl.giveRoleBox.Text),
                    TakeRole  = ulong.Parse(rl.takeRoleBox.Text)
                };
                if (_server.ReactionLockList == null)
                {
                    _server.ReactionLockList = new List <ReactionLock>();
                }
                _server.ReactionLockList.Add(newLock);
                UpdateView("reactionlock");
                BotFrame.SaveFile("servers");
            }
        }
Exemplo n.º 4
0
        private void StreamersEdit_Click(object sender, RoutedEventArgs e)
        {
            if (streamerListBox.SelectedIndex == -1)
            {
                return;
            }
            StreamerEditor se = new StreamerEditor();

            se.Owner     = this;
            se._streamer = _server.StreamerList[streamerListBox.SelectedIndex];
            se.Title     = $"Edit Streamer {se._streamer.DiscordName}";
            IsEnabled    = false;
            se.ShowDialog();
            IsEnabled = true;
            if (se.DialogResult.HasValue && se.DialogResult.Value)
            {
                se._streamer.DiscordId   = ulong.Parse(se.discordIdBox.Text);
                se._streamer.DiscordName = _client.Guilds.FirstOrDefault(x => x.Id == _server.ServerId).Users.FirstOrDefault(y => y.Id == ulong.Parse(se.discordIdBox.Text)).ToString();
                se._streamer.TwitchName  = se.twitchNameBox.Text;
                se._streamer.Mention     = (MentionLevel)se.mentionLevelComboBox.SelectedItem;
                se._streamer.GiveRole    = se.giveRoleCheckBox.IsChecked.Value;
                se._streamer.AutoPost    = se.autoPostCheckBox.IsChecked.Value;
                UpdateView("streamers");
                BotFrame.SaveFile("servers");
            }
        }
Exemplo n.º 5
0
        private async Task UserLeaveHandler(SocketGuildUser u)
        {
            var server   = _main.ServerList.FirstOrDefault(x => x.ServerId == u.Guild.Id);
            var streamer = server.StreamerList.FirstOrDefault(x => x.DiscordId == u.Id);

            if (streamer != null)
            {
                server.StreamerList.Remove(streamer);
                BotFrame.SaveFile("servers");
            }
        }
Exemplo n.º 6
0
 //Global
 private void Save_Click(object sender, RoutedEventArgs e)
 {
     //Save
     //Streamers
     //ReactionLocks
     //Settings
     if (serverPrefixCheckBox.IsChecked == true)
     {
         _server.Prefix = (PrefixChar)serverPrefixBox.SelectedItem;
     }
     if (ulong.TryParse(adminRoleBox.Text, out ulong adminRole))
     {
         _server.AdminRole = adminRole;
     }
     else
     {
         _server.AdminRole = 0;
     }
     if (ulong.TryParse(botChanBox.Text, out ulong botChan))
     {
         _server.BotChannel = botChan;
     }
     else
     {
         _server.BotChannel = 0;
     }
     if (ulong.TryParse(newUserRoleBox.Text, out ulong newUserRole))
     {
         _server.NewUserRole = newUserRole;
     }
     else
     {
         _server.NewUserRole = 0;
     }
     _server.StreamerCheckInterval = intervalSlider.Value;
     if (ulong.TryParse(streamPostChannelBox.Text, out ulong postChannel))
     {
         _server.StreamPostChannel = postChannel;
     }
     else
     {
         _server.StreamPostChannel = 0;
     }
     if (ulong.TryParse(streamerRoleBox.Text, out ulong streamerRole))
     {
         _server.StreamingRole = streamerRole;
     }
     else
     {
         _server.StreamingRole = 0;
     }
     BotFrame.SaveFile("servers");
 }
Exemplo n.º 7
0
        public async Task StreamerHandler(DiscordServer server)
        {
            server.StreamerCheckElapsed = 0;
            foreach (var streamer in server.StreamerList)
            {
                var guild      = _client.Guilds.FirstOrDefault(x => x.Id == server.ServerId);
                var streamRole = guild.Roles.FirstOrDefault(x => x.Id == server.StreamingRole);
                var channel    = guild.Channels.FirstOrDefault(x => x.Id == server.StreamPostChannel) as ISocketMessageChannel;
                var user       = guild.Users.FirstOrDefault(x => x.Id == streamer.DiscordId);

                var stream = await _api.V5.Streams.GetStreamByUserAsync((await _api.V5.Users.GetUserByNameAsync(streamer.TwitchName)).Matches[0].Id);

                if (stream.Stream == null)//not streaming
                {
                    if (streamer.Streaming)
                    {
                        streamer.Game      = "";
                        streamer.Streaming = false;
                        if (server.StreamingRole != 0 && streamer.GiveRole && user.Roles.Contains(streamRole))
                        {
                            await user.RemoveRoleAsync(streamRole);
                        }
                        BotFrame.SaveFile("servers");
                    }
                    continue;
                }
                if (!streamer.Streaming)//not marked
                {
                    streamer.Streaming = true;
                    if (server.StreamingRole != 0 && streamer.GiveRole && !user.Roles.Contains(streamRole))
                    {
                        await user.AddRoleAsync(streamRole);
                    }
                }
                if (stream.Stream.Channel.Game != streamer.Game)
                {
                    streamer.Game = stream.Stream.Channel.Game;
                    if (server.StreamPostChannel != 0 && streamer.AutoPost)
                    {
                        BotFrame.StreamPost(channel, user, stream.Stream, (int)streamer.Mention);
                    }
                    BotFrame.SaveFile("servers");
                }
            }
        }
Exemplo n.º 8
0
        private void ReactionLocksDelete_Click(object sender, RoutedEventArgs e)
        {
            if (reactionListBox.SelectedIndex == -1)
            {
                return;
            }
            IsEnabled = false;
            var res = MessageBox.Show("Are you sure you want to remove this item?", "Delete?", MessageBoxButton.YesNo, MessageBoxImage.Question);

            IsEnabled = true;
            if (res == MessageBoxResult.No)
            {
                return;
            }
            _server.ReactionLockList.Remove(_server.ReactionLockList[reactionListBox.SelectedIndex]);
            UpdateView("reactionlock");
            BotFrame.SaveFile("servers");
        }
Exemplo n.º 9
0
 private async Task ServerCheck()
 {
     if (_client == null)
     {
         return;
     }
     foreach (var connectedGuild in _client.Guilds)
     {
         DiscordServer saved = ServerList.FirstOrDefault(x => x.ServerId == connectedGuild.Id);
         if (saved != null)
         {
             if (!saved.Active)
             {
                 saved.Active = true;
             }
         }
         else
         {
             DiscordServer newServer = new DiscordServer()
             {
                 Active       = true,
                 ServerName   = connectedGuild.Name,
                 ServerId     = connectedGuild.Id,
                 Prefix       = PrefixChar.None,
                 ServerJoined = DateTime.Now.ToString()
             };
             ServerList.Add(newServer);
         }
     }
     foreach (var savedGuild in ServerList.Where(x => x.Active))
     {
         var check = _client.Guilds.FirstOrDefault(x => x.Id == savedGuild.ServerId);
         if (check == null)
         {
             savedGuild.Active = false;
         }
     }
     BotFrame.SaveFile("servers");
     ServerList.Clear();
     BotFrame.LoadFile("servers");
 }
Exemplo n.º 10
0
        private void ConsoleToken_Click(object sender, RoutedEventArgs e)
        {
            ConsoleToken tp = new ConsoleToken();

            if (BotFrame.config == null)
            {
                BotFrame.config = new Config();
            }
            if (BotFrame.config.DiscordToken != null)
            {
                tp.discordTokenBox.Text = BotFrame.config.DiscordToken;
            }
            if (BotFrame.config.TwitchToken != null)
            {
                tp.twitchTokenBox.Text = BotFrame.config.TwitchToken;
            }
            if (BotFrame.config.TwitchClientId != null)
            {
                tp.twitchClientIdBox.Text = BotFrame.config.TwitchClientId;
            }
            tp.Owner  = this;
            IsEnabled = false;
            tp.ShowDialog();
            IsEnabled = true;
            if (tp.DialogResult.HasValue && tp.DialogResult.Value)
            {
                BotFrame.config.DiscordToken   = tp.discordTokenBox.Text;
                BotFrame.config.TwitchToken    = tp.twitchTokenBox.Text;
                BotFrame.config.TwitchClientId = tp.twitchClientIdBox.Text;
                BotFrame.SaveFile("config");
                connectionButton.IsEnabled = false;
                if (BotFrame.config.DiscordToken != null || BotFrame.config.DiscordToken != "")
                {
                    connectionButton.IsEnabled = true;
                }
            }
        }
Exemplo n.º 11
0
        //Streamers
        private void StreamersAdd_Click(object sender, RoutedEventArgs e)
        {
            StreamerEditor se = new StreamerEditor();

            se.Owner = this;
            se.Title = "New Streamer";
            se.mentionLevelComboBox.SelectedItem = MentionLevel.None;
            IsEnabled = false;
            se.ShowDialog();
            IsEnabled = true;
            if (se.DialogResult.HasValue && se.DialogResult.Value)
            {
                if (_server.StreamerList.FirstOrDefault(x => x.DiscordId == ulong.Parse(se.discordIdBox.Text) || x.TwitchName == se.twitchNameBox.Text) != null)
                {
                    MessageBox.Show("You are trying to add a user that already has an entry, please select the user entry and edit it instead!", "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                Streamer newStreamer = new Streamer()
                {
                    Streaming   = false,
                    DiscordId   = ulong.Parse(se.discordIdBox.Text),
                    DiscordName = _client.Guilds.FirstOrDefault(x => x.Id == _server.ServerId).Users.FirstOrDefault(y => y.Id == ulong.Parse(se.discordIdBox.Text)).ToString(),
                    Mention     = (MentionLevel)se.mentionLevelComboBox.SelectedItem,
                    GiveRole    = se.giveRoleCheckBox.IsChecked.Value,
                    AutoPost    = se.autoPostCheckBox.IsChecked.Value,
                    TwitchName  = se.twitchNameBox.Text
                };
                if (_server.StreamerList == null)
                {
                    _server.StreamerList = new List <Streamer>();
                }
                _server.StreamerList.Add(newStreamer);
                UpdateView("streamer");
                BotFrame.SaveFile("servers");
            }
        }
Exemplo n.º 12
0
 private void ServerSave_Click(object sender, RoutedEventArgs e)
 {
     BotFrame.SaveFile("servers");
 }