예제 #1
0
        public override async void Execute(ITextChannel Channel, MessageEventArgs e, MatchCollection args)
        {
            try
            {
                await Channel.TriggerTypingIndicator();

                await Channel.CreateMessage($"Hello I'm D.va and I'm created by {BotOwner.BotOwnerName + BotOwner.BotOwnerDiscrim}\nOwner ID: {BotOwner.BotOwnerID}\nServerID: {BotOwner.BotOwnerServerID}");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
예제 #2
0
        public override async void Execute(ITextChannel Channel, MessageEventArgs e, MatchCollection args)
        {
            await Channel.TriggerTypingIndicator();

            await Channel.CreateMessage("pong");
        }
예제 #3
0
        /// <summary>
        /// Called whenever a message is send
        /// </summary>
        private static async void Gateway_OnMessageCreated(object sender, MessageEventArgs e)
        {
            DiscordMessage message = e.Message;

            if (message.Content.StartsWith("!"))
            {
                #region preparing cmdinfo
                // Ignore messages created by this bot or any other bots
                if (message.Author.IsBot)
                {
                    return;
                }

                Shard shard = e.Shard;

                // Grab the DM or guild text channel this message was posted in from cache.
                ITextChannel textChannel = (ITextChannel)shard.Cache.GetChannel(message.ChannelId);

                // Ignore all commands not from servers
                if (textChannel.ChannelType != DiscordChannelType.Guild)
                {
                    return;
                }

                // Visually represent that the bot is working on the command
                await textChannel.TriggerTypingIndicator();

                // Split message into command and arguments
                string[] splitmsg  = message.Content.Split(' ');
                string   command   = splitmsg[0].Substring(1).ToLower();
                string[] arguments = new string[splitmsg.Length - 1];
                Array.Copy(splitmsg, 1, arguments, 0, splitmsg.Length - 1);

                // Retrieve guild- and authorIDs
                ulong guildID  = ((DiscordGuildTextChannel)shard.Cache.GetChannel(message.ChannelId)).GuildId.Id;
                ulong authorID = message.Author.Id.Id;

                // Get a userProfile for the author
                UserProfile authorProfile = new UserProfile(authorID, guildID);

                // Ignore messages made by ignored users
                if (authorProfile.IsIgnored)
                {
                    return;
                }

                // Build a CommandInformation struct used to call commands
                Commands.CommandInformation cmdinfo = new Commands.CommandInformation()
                {
                    Author    = authorProfile,
                    Guild     = new GuildProfile(guildID),
                    Arguments = arguments,
                    Message   = message,
                    Shard     = shard,
                    Messaging = new Messaging(textChannel)
                };
                #endregion

                // Find the command the user requested
                foreach (var cmd in AllCommands)
                {
                    if (command == cmd.Name.ToLower())
                    {
                        // Log the send command asynchronously to keep respond time low
                        log.EnterAsync($"{message.Author.Username} sent command: '{message.Content}'");

                        if (authorProfile.PermissionLevel >= cmd.PermsRequired)
                        {
                            try
                            {
                                await cmd.RunCommand(cmdinfo);
                            }
                            catch (Commands.StopNowException stopNow)
                            {
                                throw stopNow;
                            }
                            catch (Exception exception)
                            {
                                log.Enter(exception, $"processing command '{message.Content}'");
                                await cmdinfo.Messaging.Send("The SaftBot ran into a problem processing your command. If this has happend before, " +
                                                             "please make a bug report here: https://github.com/loglob/SaftbotNET/issues");
                            }
                        }
                        else
                        {
                            await cmdinfo.Messaging.NoPerms();
                        }
                    }
                }
            }
        }