public Settings(DiscordClient clientref) { mainClientReference = clientref; InitializeComponent(); SetupTheme(); LoadSettings(); }
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(); }
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 } }
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 } }
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(); }
public MessageStub(DiscordMessage message, DiscordClient refer) { mainClientReference = refer; InitializeComponent(); Message = message; RefreshContent(); #if DEBUG richTextBox.MouseDoubleClick += RichTextBox_MouseDoubleClick; #endif }
private static void Init() { _client = new DiscordClient { ClientPrivateInformation = { email = ClientConfiguration.Email, password = ClientConfiguration.Password } }; }
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(); }
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); } }
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); } } } }
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 } }
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(); }); }
public DiscordMember(DiscordClient parent) { Roles = new List<DiscordRole>(); }
public DiscordUser(DiscordClient p) { __parent = p; }
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. }
// 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);
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(); }
public DiscordVoiceClient(DiscordClient parentClient, DiscordVoiceConfig config) { _parent = parentClient; VoiceConfig = config; InitializeOpusEncoder(); }
public override void Run(DiscordClient client, DiscordPrivateMessageEventArgs e, string[] args) { client.SendMessageToUser("Pong", e.author); }
public CustomWebSocket(DiscordClient _parent) { ___parent = _parent; _sendQueue = new ConcurrentQueue <string>(); }
//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); }
public void DoLogin() { string botToken = File.ReadAllText("bot_token_important.txt"); client = new DiscordClient(botToken.Trim(), true); client.WriteLatestReady = true; SetupEvents(cancelToken); }
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; }
public DiscordVoiceClient(DiscordClient parentClient) { _parent = parentClient; VoiceConfig = new DiscordVoiceConfig(); InitializeOpusEncoder(); }
public DiscordVoiceClient(DiscordClient parent) { _parent = parent; }
/// <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 } }; }
public CustomWebSocket(DiscordClient _parent) { ___parent = _parent; _sendQueue = new ConcurrentQueue<string>(); }
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 { } } }