示例#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);
            }
        }
示例#2
0
        public async Task Ping(CommandContext ctx, string cmd, [RemainingText] string args)
        {
            logger.Info("ping Command", Useful.GetDiscordName(ctx));

            switch (cmd)
            {
            case "add":
                PingUser.PingControlAdd(ctx.Member.Id, args);
                break;

            case "remove":
                PingUser.PingControlRemove(ctx.Member.Id, args);
                break;

            case "info":
                if (ctx.Guild.Members.TryGetValue(ctx.Message.Author.Id, out DiscordMember member))
                {
                    await PingUser.PingControlInfo(member).ConfigureAwait(false);
                }
                break;
            }
            PingUser.SavePings(PingUser.Pings);
        }