Пример #1
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
            }
        }
Пример #2
0
 void OnPrivateMessageReceived(object sender, DiscordPrivateMessageEventArgs e)
 {
     Respond(e.Author,
             e.Message.Substring(1),
             e.Channel,
             (response) => { e.Author.SendMessage(response); });
 }
Пример #3
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
            }
        }
Пример #4
0
        // TODO Implement permissions system
        // Is having this event handler as async even useful?
        private static async void _client_PrivateMessageReceived(object sender, DiscordPrivateMessageEventArgs e)
        {
            Console.WriteLine($"Private Message <- [{e.author.Username} ({e.author.ID})]: \"{e.message}\"");
            string[] parts = e.message.Split(' ');
            string   cmd   = parts.First();

            // Redundant Lookups
            if (Command.Lookup(cmd) == null)
            {
                _client.SendMessageToUser("Command not found", e.author);
            }
            else if (Member.GetMemberById(e.author.ID).IsPermitted(cmd))
            {
                string[] cmdArgs = new string[parts.Length - 1];

                for (int i = 1; i < parts.Length; i++)
                {
                    cmdArgs[i - 1] = parts[i];
                }

                // Redundant Lookups
                // TODO Implement error reporting
                await Task.Run(() => Command.Lookup(cmd).Run(_client, e, cmdArgs));
            }
            else
            {
                _client.SendMessageToUser("You do not have permission to run this command", e.author);
            }
        }
Пример #5
0
        /// <summary>
        /// Called when Discord sends us a private message.
        /// </summary>
        /// <param name="o">The o.</param>
        /// <param name="args">The <see cref="DiscordPrivateMessageEventArgs"/> instance containing the event data.</param>
        private void PrivateMessageReceived(object o, DiscordPrivateMessageEventArgs args)
        {
            if (_receivedMessage != null)
            {
                foreach (IMessage message in _waitingMessages)
                {
                    _receivedMessage(message);
                }
                _waitingMessages.Clear();

                _receivedMessage(new Message(args));
            }
            else
            {
                _waitingMessages.Add(new Message(args));
            }
        }
Пример #6
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
            }
        }
Пример #7
0
        public static void HandlePrivateMessage(object sender, DiscordPrivateMessageEventArgs e)
        {
            DiscordMember author  = e.Author;
            string        message = e.Message;

            if (message.StartsWith("!"))
            {
                /*CommandSection*/
                string[] splits = message.Split(' ');
                if (splits.Length > 0)
                {
                    string command = splits[0];
                    if (command.ToLower().Equals("!join"))
                    {
                        if (splits.Length > 1)
                        {
                            string link       = splits[1];
                            string inviteCode = link.Split('/').Length == 3 ? link.Split('/')[3] : "0000";
                            Logger.LogRequestCommand("JOIN", e.Author.Username, inviteCode);
                            if (bot != null)
                            {
                                bot.AcceptInvite(link);
                            }
                        }

                        e.Author.SendMessage("Tried to join the Server, see you there!");
                        Logger.LogActualServerTree(bot.GetServersList());
                    }
                    if (command.ToLower().Equals("!echo"))
                    {
                        string toEcho = e.Message.Substring(6);
                        Logger.LogRequestCommand("ECHO", e.Author.Username, toEcho);
                        e.Author.SendMessage(toEcho);
                    }
                }
            }
        }
Пример #8
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);
Пример #9
0
 public static void LogPrivateMessage(object sender, DiscordPrivateMessageEventArgs e)
 {
     Console.ForegroundColor = ConsoleColor.Cyan;
     Console.WriteLine("[PRIVMSG]" + e.Author.Username + ":" + e.Message);
     Console.ResetColor();
 }
Пример #10
0
 public override void Run(DiscordClient client, DiscordPrivateMessageEventArgs e, string[] args)
 {
     client.SendMessageToUser("Pong", e.author);
 }