Ejemplo n.º 1
0
 public Settings(DiscordClient clientref)
 {
     mainClientReference = clientref;
     InitializeComponent();
     SetupTheme();
     LoadSettings();
 }
Ejemplo n.º 2
0
        public MainWindow()
        {
            InitializeComponent();

            if (!App.ClientConfiguration.Settings.UseWindows10Notifications)
            {
                notificationIcon = new NotifyIcon();
                notificationIcon.Text = "Dissonance";
                notificationIcon.Visible = true;
                notificationIcon.Icon = CustomDiscordClient.Properties.Resources.taskbar;
                notificationIcon.BalloonTipIcon = ToolTipIcon.None;
            }

            Icon = new BitmapImage(MagicalDiscordIcon);
            //channelsList.Visibility = Visibility.Hidden;

            MainClient = new DiscordClient();
            MainClient.RequestAllUsersOnStartup = true;

            SetupEvents();

            Title = "Dissonance - Connecting..";
            Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;

            if(MainClient.SendLoginRequest() != null)
                discordTask = Task.Run(() => MainClient.Connect());

            openServerViews = new List<ServerView>();

            SettingsGearClicked += MainWindow_SettingsGearClicked;

            SetupTheme();
        }
        public MainWindow()
        {
            InitializeComponent();

            #if WIN10NOTIF
            #else
            notificationIcon = new NotifyIcon();
            notificationIcon.Text = "WPF Discord";
            notificationIcon.Visible = true;
            notificationIcon.Icon = CustomDiscordClient.Properties.Resources.taskbar;
            notificationIcon.BalloonTipIcon = ToolTipIcon.None;
            #endif

            Icon = new BitmapImage(MagicalDiscordIcon);
            //channelsList.Visibility = Visibility.Hidden;

            MainClient = new DiscordClient();
            MainClient.RequestAllUsersOnStartup = true;

            SetupEvents();

            Title = "Connecting..";
            Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;

            if(MainClient.SendLoginRequest() != null)
                discordTask = Task.Run(() => MainClient.Connect());

            openServerViews = new List<ServerView>();

            SetupTheme();
        }
Ejemplo n.º 4
0
        public override void Run(DiscordClient client, DiscordPrivateMessageEventArgs e, string[] args)
        {
            if (args.Length > 0)
            {
                switch (args[0])
                {
                    case "Commands":
                        ReloadCommands();
                        client.SendMessageToUser("Reloaded all commands", e.author);
                        break;

                    case "Permissions":
                        Member.ReloadMembers();
                        Role.ReloadRoles();
                        client.SendMessageToUser("Reloaded permissions", e.author);
                        break;

                    default:
                        client.SendMessageToUser($"Could not reload \"{args[0]}.\" I do not recognize that.", e.author);
                        break;
                }
            }
            else
            {
                // TODO Implement standard Exception system to handle error messages in the command runner
            }
        }
Ejemplo n.º 5
0
        public override void Run(DiscordClient client, DiscordPrivateMessageEventArgs e, string[] args)
        {
            // TODO Add this argument length checking to command runner
            if (args.Length > 0)
            {
                switch (args[1])
                {
                    case "UserId":
                        if (args[0] == "My")
                        {
                            args[0] = e.author.ID;
                        }

                        // Search through all members on the server for the matching username/id

                        client.SendMessageToUser($"UserId: {e.author.ID}", e.author);
                        break;

                    default:
                        client.SendMessageToUser($"Property \"{args[1]}\" not recognized", e.author);
                        break;
                }
            }
            else
            {
                // TODO Implement standard Exception system to handle error messages in the command runner
            }
        }
Ejemplo n.º 6
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello world!");
            Console.ReadLine();

            Console.WriteLine("Running Discord bot test...");
            test = new DiscordClient();
            test.LoginInformation = new DiscordLoginInformation();
            test.LoginInformation.email[0] = "*****@*****.**";
            test.LoginInformation.password[0] = "papabear12";
            Console.WriteLine("Attempting login..");
            //Console.WriteLine("out: {0}", test.SendLoginRequest());
            try
            {
                Thread t = new Thread(InputThread);
                t.Start();
                test.MessageReceived += (sender, e) =>
                {
                    Console.WriteLine("[- Message from {0} in {1} on {2}: {3}", e.username, e.ChannelName, e.ServerName, e.message);
                    if (e.message.StartsWith("?status"))
                        test.SendMessageToChannel("I work ;)", e.ChannelName, e.ServerName);
                };
                test.SendLoginRequest();
                Thread tt = new Thread(test.ConnectAndReadMessages);
                tt.Start();
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadLine();
        }
 public ServerView(DiscordServer server, DiscordClient client)
 {
     InitializeComponent();
     mainClientReference = client;
     Server = server;
     RefreshContent();
     SetTheme();
 }
Ejemplo n.º 8
0
        public MessageStub(DiscordMessage message, DiscordClient refer)
        {
            mainClientReference = refer;
            InitializeComponent();
            Message = message;
            RefreshContent();
#if DEBUG
            richTextBox.MouseDoubleClick += RichTextBox_MouseDoubleClick;
#endif
        }
Ejemplo n.º 9
0
 private static void Init()
 {
     _client = new DiscordClient
     {
         ClientPrivateInformation =
         {
             email = ClientConfiguration.Email,
             password = ClientConfiguration.Password
         }
     };
 }
Ejemplo n.º 10
0
	static void Main(string[] args){
		DiscordClient client = new DiscordClient();
		client.ClientPrivateInformation.Email= "*****@*****.**";
		client.ClientPrivateInformation.Password="******";
		client.MessageReceived += (s,e) => {
			if(e.MessageText == "!test"){
				e.Channel.SendMessage("Ayy");
			}};
		client.SendLoginRequest();
		Thread connect = new Thread(client.Connect);
		connect.Start();
}
Ejemplo n.º 11
0
        public TestServerLog(DiscordClient client)
        {
            Name = "discordsharp-logs";
            Description = "nunya";

            DiscordSharpTestServer = client.GetServersList().Find(
                x => x.Name == "DiscordSharp Test Server"
            ); //todo replace with id
            if(DiscordSharpTestServer != null)
            {
                LogChannel = DiscordSharpTestServer.Channels.Find(x => x.Name == "log" && x.Type == ChannelType.Text);
            }
        }
Ejemplo n.º 12
0
        public UserInfo(DiscordMember member, DiscordClient client)
        {
            InitializeComponent();
            SetupTheme();

            Member = member;
            mainClientReference = client;

            if(Member.Avatar != null)
            {
                BitmapImage _userAvatar = new BitmapImage(Member.GetAvatarURL());
                Icon = _userAvatar;
                try
                {
                    userAvatar.Source = _userAvatar;
                }
                catch (Exception) { }
            }
            usernameLabel.Content = Member.Username + $" (#{Member.Discriminator})";
            Title = "User info for " + Member.Username;
            if (member.CurrentGame != null)
                userID.Content = $"Playing {member.CurrentGame}";
            else
                userID.Content = "";

            foreach(var server in mainClientReference.GetServersList())
            {
                foreach(var __member in server.members)
                {
                    if(__member.ID == member.ID)
                    {
                        ServerStub stub = new ServerStub(server);
                        inServers.Items.Add(stub);
                    }
                }
            }
            
        }
Ejemplo n.º 13
0
        public override void Run(DiscordClient client, DiscordPrivateMessageEventArgs e, string[] args)
        {
            if (args.Length > 0)
            {
                Command command = Lookup(args[0]);
                string response;

                if (command == null)
                {
                    response = $"Command \"{args[0]}\" not recognized, make sure you spelled the command correctly.";
                }
                else
                {
                    response = command.GetUsage();
                }

                client.SendMessageToUser(response, e.author);
            }
            else
            {
                // TODO Implement standard Exception system to handle error messages in the command runner
            }
        }
Ejemplo n.º 14
0
 static Task ClientTask(DiscordClient client)
 {
     return Task.Run(() =>
     {
         client.MessageReceived += (sender, e) =>
         {
             if (e.message.content.StartsWith("?joinvoice"))
             {
                 string[] split = e.message.content.Split(new char[] { ' ' }, 2);
                 if (split[1] != "")
                 {
                     DiscordChannel toJoin = e.Channel.parent.channels.Find(x => (x.Name.ToLower() == split[1].ToLower()) && (x.Type == ChannelType.Voice));
                     if (toJoin != null)
                     {
                         client.ConnectToVoiceChannel(toJoin);
                     }
                 }
             }
             else if (e.message.content.StartsWith("?voice"))
             {
                 string[] split = e.message.content.Split(new char[] { ' ' }, 2);
                 if (File.Exists(split[1]))
                     DoVoice(client.GetVoiceClient(), split[1]);
             }
             else if(e.message.content.StartsWith("?disconnect"))
             {
                 client.DisconnectFromVoice();
             }
         };
         client.Connected += (sender, e) =>
         {
             Console.WriteLine("Connected as " + e.user.Username);
         };
         client.Connect();
     });
 }
Ejemplo n.º 15
0
 public DiscordMember(DiscordClient parent)
 {
     Roles = new List<DiscordRole>();
 }
Ejemplo n.º 16
0
 public DiscordUser(DiscordClient p)
 {
     __parent = p;
 }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            // First of all, a DiscordClient will be created, and the email and password will be defined.
            Console.WriteLine("Defining variables");
            DiscordClient client = new DiscordClient();
            client.ClientPrivateInformation.Email = "";
            client.ClientPrivateInformation.Password = "";

            // Then, we are going to set up our events before connecting to discord, to make sure nothing goes wrong.

            Console.WriteLine("Defining Events");
            client.Connected += (sender, e) => // Client is connected to Discord
            {
                Console.WriteLine("Connected! User: "******"Bot online!"); // This will display at "Playing: "
                //Whoops! i messed up here. (original: Bot online!\nPress any key to close this window.)
            };


            client.PrivateMessageReceived += (sender, e) => // Private message has been received
            {
                if (e.Message == "help")
                {
                    e.Author.SendMessage("This is a private message!");
                    // Because this is a private message, the bot should send a private message back
                    // A private message does NOT have a channel
                }
                if (e.Message.StartsWith("join "))
                {
                    string inviteID = e.Message.Substring(e.Message.LastIndexOf('/') + 1);
                    // Thanks to LuigiFan (Developer of DiscordSharp) for this line of code!
                    client.AcceptInvite(inviteID);
                    e.Author.SendMessage("Joined your discord server!");
                    Console.WriteLine("Got join request from " + inviteID);
                }
            };


            client.MessageReceived += (sender, e) => // Channel message has been received
            {
                if (e.MessageText == "help")
                {
                    e.Channel.SendMessage("This is a public message!");
                    // Because this is a public message, 
                    // the bot should send a message to the channel the message was received.
                }
            };

            //  Below: some things that might be nice?

            //  This sends a message to every new channel on the server
            client.ChannelCreated += (sender, e) =>
                {
                    e.ChannelCreated.SendMessage("Nice! a new channel has been created!");
                };

            //  When a user joins the server, send a message to them.
            client.UserAddedToServer += (sender, e) =>
                {
                    e.AddedMember.SendMessage("Welcome to my server! rules:");
                    e.AddedMember.SendMessage("1. be nice!");
                    e.AddedMember.SendMessage("- Your name!");
                };

            //  Don't want messages to be removed? this piece of code will
            //  Keep messages for you. Remove if unused :)
            client.MessageDeleted += (sender, e) =>
                {
                    e.Channel.SendMessage("Removing messages has been disabled on this server!");
                    e.Channel.SendMessage("<@" + e.DeletedMessage.Author.ID + "> sent: " +e.DeletedMessage.Content.ToString());
                };

            // Now, try to connect to Discord.
            try{ 
                // Make sure that IF something goes wrong, the user will be notified.
                // The SendLoginRequest should be called after the events are defined, to prevent issues.
                Console.WriteLine("Sending login request");
                client.SendLoginRequest();
                Console.WriteLine("Connecting client in separate thread");
                Thread connect = new Thread(client.Connect);
                connect.Start();
                 // Login request, and then connect using the discordclient i just made.
                Console.WriteLine("Client connected!");
            }catch(Exception e){
                Console.WriteLine("Something went wrong!\n" + e.Message + "\nPress any key to close this window.");
            }

            // Done! your very own Discord bot is online!


            // Now to make sure the console doesnt close:
            Console.ReadKey(); // If the user presses a key, the bot will shut down.
            Environment.Exit(0); // Make sure all threads are closed.
        }
Ejemplo n.º 18
0
 // Should I change run to return a string that is sent back to the user?
 // This could easily allow adding a Pipe operator
 public abstract void Run(DiscordClient client, DiscordPrivateMessageEventArgs e, string[] args);
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            client = new DiscordClient();
            if(File.Exists("credentials.txt"))
            {
                using (StreamReader sr = new StreamReader("credentials.txt"))
                {
                    client.ClientPrivateInformation.email = sr.ReadLine();
                    client.ClientPrivateInformation.password = sr.ReadLine();
                    sr.Close();
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("Error");
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write(" Please create credentials.txt with email and password for bot.");

                Console.ReadLine();
            }

            if (client.SendLoginRequest() != null)
                ClientTask(client);

            Console.ReadLine();
        }
Ejemplo n.º 20
0
 public DiscordVoiceClient(DiscordClient parentClient, DiscordVoiceConfig config)
 {
     _parent = parentClient;
     VoiceConfig = config;
     InitializeOpusEncoder();
 }
Ejemplo n.º 21
0
 public override void Run(DiscordClient client, DiscordPrivateMessageEventArgs e, string[] args)
 {
     client.SendMessageToUser("Pong", e.author);
 }
Ejemplo n.º 22
0
 public CustomWebSocket(DiscordClient _parent)
 {
     ___parent  = _parent;
     _sendQueue = new ConcurrentQueue <string>();
 }
Ejemplo n.º 23
0
        //yes, this is a bullet for my valentine reference
		private void LetsGoAgain()
		{
			client.Dispose ();
			client = null;

			string botToken = File.ReadAllText("bot_token_important.txt");
			client = new DiscordClient(botToken, true);
			client.RequestAllUsersOnStartup = true;
            
			client.ClientPrivateInformation.Email = config.BotEmail;
			client.ClientPrivateInformation.Password = config.BotPass;

			SetupEvents(cancelToken);
		}
Ejemplo n.º 24
0
 public void DoLogin()
 {
     string botToken = File.ReadAllText("bot_token_important.txt");
     client = new DiscordClient(botToken.Trim(), true);
     client.WriteLatestReady = true;
     SetupEvents(cancelToken);
 }
Ejemplo n.º 25
0
        private async Task<bool> doLoginStuff(string user, string pass)
        {
            bool returnval = false;

            await Task.Run(() =>
            {
                DiscordClient tempClient = new DiscordClient();
                tempClient.ClientPrivateInformation = new DiscordUserInformation { email = user, password = pass };
                if (tempClient.SendLoginRequest() != null)
                {
                    returnval = true;
                }
                else
                    returnval = false;
            });

            return returnval;
        }
Ejemplo n.º 26
0
 public DiscordVoiceClient(DiscordClient parentClient)
 {
     _parent = parentClient;
     VoiceConfig = new DiscordVoiceConfig();
     InitializeOpusEncoder();
 }
Ejemplo n.º 27
0
 public DiscordVoiceClient(DiscordClient parent)
 {
     _parent = parent;
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Basic initializations for the bot such as commands and events
 /// </summary>
 private void InitBot()
 {
     _client = new DiscordClient();
     _client.MessageReceived += (sender, e) =>
     {
         if (e.message.author.user.id != _client.Me.user.id)
         {
             _messages.Add(e.message);
             if (MessageProcessor.ValidCommand(e.message))
             {
                 string[] parsed = MessageProcessor.ProcessMessage(e.message);
                 _commands[parsed[0]].Invoke(parsed[1], e.message);
             }
             if (MessagesUpdated != null)
             {
                 MessagesUpdated(this, EventArgs.Empty);
             }
         }
     };
     _commands = new Dictionary<string, Func<string, DiscordMessage, bool>>
     {
         {"invite", AcceptInviteComm},
         {"ping", PingComm},
         {"clear", ClearComm},
         {"auth", AuthorizeComm},
         {"me", MeComm},
         {"disconnect", DisconnectComm},
         {"timer", TimerComm },
         {"setstatus", SetStatus },
         {"status", GetStatus }
     };
 }
Ejemplo n.º 29
0
        public CustomWebSocket(DiscordClient _parent)
        {
            ___parent = _parent;
            _sendQueue = new ConcurrentQueue<string>();

        }
Ejemplo n.º 30
-1
        private void SendVoice(string file, DiscordClient client, YouTubeVideo video)
        {
            DiscordVoiceClient vc = client.GetVoiceClient();
            try
            {
                int ms = vc.VoiceConfig.FrameLengthMs;
                int channels = vc.VoiceConfig.Channels;
                int sampleRate = 48000;

                int blockSize = 48 * 2 * channels * ms; //sample rate * 2 * channels * milliseconds
                byte[] buffer = new byte[blockSize];
                var outFormat = new WaveFormat(sampleRate, 16, channels);

                vc.SetSpeaking(true);

                if(video.AudioFormat == AudioFormat.Mp3)
                {
                    using (var mp3Reader = new Mp3FileReader(video.Stream()))
                    {
                        using (var resampler = new MediaFoundationResampler(mp3Reader, outFormat) { ResamplerQuality = 60 })
                        {
                            //resampler.ResamplerQuality = 60;
                            int byteCount;
                            while ((byteCount = resampler.Read(buffer, 0, blockSize)) > 0)
                            {
                                if (vc.Connected)
                                {
                                    vc.SendVoice(buffer);
                                }
                                else
                                    break;
                            }
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine("Voice finished enqueuing");
                            Console.ForegroundColor = ConsoleColor.White;
                            resampler.Dispose();
                            mp3Reader.Close();
                        }
                    }
                }
                else if(video.AudioFormat == AudioFormat.Vorbis)
                {
                    using (var vorbis = new NAudio.Vorbis.VorbisWaveReader(video.Stream()))
                    {
                        using (var resampler = new MediaFoundationResampler(vorbis, outFormat) { ResamplerQuality = 60 })
                        {
                            int byteCount;
                            while ((byteCount = resampler.Read(buffer, 0, blockSize)) > 0)
                            {
                                if (vc.Connected)
                                {
                                    vc.SendVoice(buffer);
                                }
                                else
                                    break;
                            }
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine("Voice finished enqueuing");
                            Console.ForegroundColor = ConsoleColor.White;
                            resampler.Dispose();
                            vorbis.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                try
                {
                    MainEntry.owner.SendMessage("Exception during voice: `" + ex.Message + "`\n\n```" + ex.StackTrace + "\n```");
                }
                catch { }
            }
        }