Exemple #1
0
        public double CheckCoolDown(DSharpPlus.Entities.DiscordMessage msg)
        {
            var currentMessage = msg.Timestamp.DateTime;
            var timeElapsed    = currentMessage.Subtract(previousCommandTime).TotalSeconds;

            if (allowCommand || timeElapsed >= cooldownTime) //we are allowed to run the command!
            {
                allowCommand = false;
                return(-1);
            }
            else
            {
                return(Math.Round(cooldownTime - timeElapsed));
            }
        }
Exemple #2
0
        public bool ActivateCommand(DSharpPlus.Entities.DiscordMessage message, AccessLevel access)
        {
            try
            {
                if (message == null || string.IsNullOrEmpty(message.Content) || char.IsLetterOrDigit(message.Content[0]))
                {
                    return(false);
                }

                if (ActiveCommands == null)
                {
                    ActiveCommands = new List <ICommand>();
                }

                string[] cmdsplit = message.Content.Split(' ');

                if (cmdsplit == null || cmdsplit.Length == 0)
                {
                    return(false);
                }

                ulong  id        = message.Author.Id;
                string name      = message.Author.Username;
                var    guild     = message.Channel.Guild;
                var    guildid   = (ulong?)message.Channel.GuildId;
                ulong  chid      = message.Channel.Id;
                char   activator = message.Content[0];
                string _cmd      = cmdsplit[0].Substring(1, cmdsplit[0].Length - 1);
                string aftercmd  = "";
                if (message.Content.Length > cmdsplit[0].Length + 1)
                {
                    aftercmd = message.Content.Remove(0, cmdsplit[0].Length + 1);
                }

                CommandEventArg arg = new CommandEventArg(id, name, (guild == null ? (ulong?)null : guildid), chid, activator, _cmd, aftercmd);


                ICommand cmd = null;

                //For now i hardcode this cause I'm lazy
                if (activator.Equals('>'))
                {
                    Console.WriteLine(">");
                    //TextCommand.OnTextCommand(arg);
                    return(true);
                }

                cmd = ActiveCommands.Find(cmd_ => cmd_.Activator.Equals(arg.Activator) && cmd_.CMD.Equals(arg.CMD));

                if (cmd == null)
                {
                    return(false);
                }

                if ((int)cmd.AccessLevel > (int)access)
                {
                    return(false);
                }

                using (Database.GAFContext context = new Database.GAFContext())
                {
                    int dbid  = context.BotMaintenance.Max(m => m.Id);
                    var maint = context.BotMaintenance.FirstOrDefault(m => m.Id == dbid);

                    if (maint.Enabled && access < AccessLevel.Admin)
                    {
                        Coding.Discord.SendMessage(chid, "Bot is currently in maintenance, please try again later" + Environment.NewLine +
                                                   "Info: " + maint.Notification ?? "no information");

                        return(false);
                    }
                }

                cmd.Activate(arg);

                return(true);
            }
            catch (Exception ex)
            {
                Logger.Log(ex.ToString(), LogLevel.Trace);
                return(false);
            }
        }
Exemple #3
0
namespace GreenSharp { public static class EmbedHelper { public static DSharpPlus.Entities.DiscordEmbed Embed(this DSharpPlus.Entities.DiscordMessage msg, DSharpPlus.DiscordClient client, System.String title, System.String description) => new DSharpPlus.Entities.DiscordEmbedBuilder
                                                         {
                                                             Title = title, Description = description, Author = new DSharpPlus.Entities.DiscordEmbedBuilder.EmbedAuthor {
                                                                 Name = $"{msg.Author.Username}#{msg.Author.Discriminator}, ", IconUrl = msg.Author.GetAvatarUrl(DSharpPlus.ImageFormat.Auto, 2048)
                                                             }, Footer = new DSharpPlus.Entities.DiscordEmbedBuilder.EmbedFooter {
                                                                 IconUrl = client.CurrentUser.GetAvatarUrl(DSharpPlus.ImageFormat.Auto, 2048), Text = $"Bot: {client.CurrentUser.Username}"
                                                             }
                                                         }; public static System.String BetterMention(this DSharpPlus.Entities.DiscordUser user) => $"<@{user.Id}>"; } }