예제 #1
0
        [Aliases("p")]                          // alternative names for the command
        public async Task Ping(CommandContext ctx)
        {
            Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss] ", CultureInfo.CreateSpecificCulture("en-GB")) + "ping Command");

            string msg, cmd, args;

            try
            {
                msg  = ctx.Message.Content.ToLower(CultureInfo.CreateSpecificCulture("en-GB")).Split(new char[] { ' ' }, 2)[1]; // remove !p or !ping
                cmd  = msg.Split(new char[] { ' ' }, 2)[0];                                                                     // get command word
                args = Useful.GetBetween(msg, cmd + " ", null);                                                                 // get words after command, add a space to cmd word so args doesnt start with one
            }
            catch (IndexOutOfRangeException)
            {
                return;
            }

            if (!string.IsNullOrWhiteSpace(msg))
            {
                ulong userNameID  = ctx.Member.Id; // get message creators username in lower case
                var   discordUser = ctx.Message.Author;
                await PingUser.PingControl(userNameID, discordUser, cmd, args).ConfigureAwait(false);

                PingUser.SavePings(PingUser.Pings);
            }
        }