예제 #1
0
        private static Task SubscribeEventLoggerSettingsBotVar(SocketGuild guild)
        {
            BotVarCollection collection = BotVarManager.GetGuildBotVarCollection(guild.Id);

            collection.SubscribeToBotVarUpdateEvent(EventLogger.OnBotVarUpdatedGuild, "logChannels");
            return(Task.CompletedTask);
        }
예제 #2
0
        public override bool PreconditionCheckGuild(IGuildCommandContext context, out string message)
        {
            GuildBotVarCollection BotVarCollection = BotVarManager.GetGuildBotVarCollection(context.Guild.Id);

            if (!BotVarCollection.TryGetBotVar(BotVarId, out ulong roleId))
            {
                message = $"The guild config variable `{BotVarId}` has to be set to the correct role id!";
                return(false);
            }
            bool hasRole = context.GuildUser.Roles.Any(role =>
            {
                if (role.Id == roleId)
                {
                    if (roleMention == null)
                    {
                        roleMention = role.Mention;
                    }
                    return(true);
                }
                return(false);
            });

            if (!hasRole)
            {
                message = $"You do not have required role {(roleMention == null ? Markdown.InlineCodeBlock(roleId) : roleMention)}!";
            }
            else
            {
                message = null;
            }
            return(hasRole);
        }
예제 #3
0
        public static GuildChannelMeta GetDefaultOrSaved(ulong guildId, ulong channelId)
        {
            GuildBotVarCollection guildBotVarCollection = BotVarManager.GetGuildBotVarCollection(guildId);

            if (!guildBotVarCollection.TryGetBotVar($"{channelId}.meta", out GuildChannelMeta channelMeta))
            {
                channelMeta = GetDefault(guildId);
            }
            return(channelMeta);
        }
예제 #4
0
 private static async Task <string> retrieveToken()
 {
     if (!BotVarManager.TryGetBotVar("discordtoken", out string discordToken))
     {
         Console.WriteLine("BotCore could not find the bot token config variable. Enter the bot token now:");
         discordToken = Console.ReadLine();
         BotVarManager.SetBotVar("discordtoken", discordToken);
         await BotVarManager.SaveBotVars();
     }
     return(discordToken);
 }
예제 #5
0
        private static void SetupBotVarDefaults()
        {
            BotVar defaultColor = new BotVar("embedcolor", new ColorBotVar(new Color(255, 255, 255)));

            BotVarManager.SetDefault(defaultColor);
            BotVarManager.SubscribeToBotVarUpdateEvent(OnBotVarUpdated, "botadmins", "embedcolor");

            MessageHandler.SetupBotVarSubscription();
            ExceptionHandler.SetupBotVar();

            OnBotVarDefaultSetup();
        }
예제 #6
0
 public static GuildChannelMeta GetDefault(ulong guildId)
 {
     if (!guildDefaults.TryGetValue(guildId, out GuildChannelMeta guildDefault))
     {
         GuildBotVarCollection guildBotVarCollection = BotVarManager.GetGuildBotVarCollection(guildId);
         if (!guildBotVarCollection.TryGetBotVar("defaultguildchannelmeta", out guildDefault))
         {
             guildDefault = new GuildChannelMeta();
         }
         guildDefaults.Add(guildId, guildDefault);
         guildBotVarCollection.SubscribeToBotVarUpdateEvent(OnBotVarUpdated, "defaultguildchannelmeta");
     }
     return(guildDefault);
 }
예제 #7
0
        private static async Task LoadOrGenerateBotVars()
        {
            bool loadsuccess = await BotVarManager.TryLoadBotVars();

            await Resources.LoadGuildFiles();

            if (!loadsuccess)
            {
                Console.WriteLine("BotCore couldn't load config variables. Create a new config variable file now? Y/N");
                if (Console.ReadLine().ToLower().StartsWith('y'))
                {
                    Directory.CreateDirectory(Resources.BaseDirectory);
                    await BotVarManager.SaveBotVars();
                }
            }
        }
        private static async Task Client_UserLeft(SocketGuildUser user)
        {
            if (MinecraftGuildModel.TryGetGuildOfUser(user.Id, out MinecraftGuild userGuild))
            {
                GuildRank rank = userGuild.GetMemberRank(user.Id);
                if (rank == GuildRank.Captain)
                {
                    await AdminTaskInteractiveMessage.CreateAdminTaskMessage($"Guild Captain left Server", $"Guild: `{userGuild.Name}`\nCaptain: `{user}`, Id: `{user.Id}`{(string.IsNullOrEmpty(user.Nickname) ? "" : $", Nickname: `{user.Nickname}`")}");
                }
                else
                {
                    userGuild.MemberIds.Remove(user.Id);
                    userGuild.MateIds.Remove(user.Id);
                    await MinecraftGuildModel.SaveAll();
                }
            }
            BotVarCollection guildBotVars = BotVarManager.GetGuildBotVarCollection(user.Guild.Id);

            if (guildBotVars.TryGetBotVar(Var.MinecraftBranchRoleBotVarId, out ulong minecraftBranchRole))
            {
                if (user.Roles.Any(role => { return(role.Id == minecraftBranchRole); }))
                {
                    await AdminTaskInteractiveMessage.CreateAdminTaskMessage($"Minecraft Branch Member left Server", $"Name: `{user}`, Id: `{user.Id}`{(string.IsNullOrEmpty(user.Nickname) ? "" : $", Nickname: `{user.Nickname}`")}");
                }
            }

            if (TryGetLogChannel(user.Guild, DiscordEventType.UserLeft, out SocketTextChannel channel, out EmbedBuilder embed))
            {
                embed.Title = $"{user} left";
                StringBuilder description = new StringBuilder();
                if (!string.IsNullOrEmpty(user.Nickname))
                {
                    description.AppendLine($"**Nickname**: \"{user.Nickname}\"");
                }
                if (user.Roles.Count > 1)
                {
                    description.AppendLine($"**Roles**: `{string.Join(", ", user.Roles)}`");
                }
                embed.ThumbnailUrl = user.GetDefaultAvatarUrl();
                embed.Description  = description.ToString();
                await channel.SendEmbedAsync(embed);
            }
        }
예제 #9
0
 internal static void SetupBotVar()
 {
     BotVarManager.SubscribeToBotVarUpdateEvent(OnBotVarsUpdated, "exceptionhandler.guildid", "exceptionhandler.roleid", "exceptionhandler.channelid");
 }
예제 #10
0
        protected override Task <ArgumentParseResult> ParseArguments(IDMCommandContext context)
        {
            if (context.Arguments.TotalCount == 0)
            {
                mode = CommandMode.listall;
                return(Task.FromResult(ArgumentParseResult.DefaultNoArguments));
            }

            if (context.Arguments.First.ToLower() == "save")
            {
                mode = CommandMode.save;
                return(Task.FromResult(ArgumentParseResult.SuccessfullParse));
            }

            BotVarId = context.Arguments.First;
            BotVarManager.TryGetBotVar(BotVarId, out BotVar);

            if (context.Arguments.TotalCount == 1)
            {
                mode = CommandMode.get;
                if (BotVar.IsDefined)
                {
                    return(Task.FromResult(ArgumentParseResult.SuccessfullParse));
                }
                else
                {
                    return(Task.FromResult(new ArgumentParseResult(Arguments[0], $"Couldn't locate a config variable named `{BotVarId}`!")));
                }
            }
            else
            {
                mode = CommandMode.set;
            }

            context.Arguments.Index++;

            if (context.Arguments.First.ToLower() == "delete")
            {
                mode = CommandMode.delete;
                if (!BotVar.IsDefined)
                {
                    return(Task.FromResult(new ArgumentParseResult(Arguments[0], $"Couldn't locate a config variable named `{BotVarId}`!")));
                }
                else
                {
                    return(Task.FromResult(ArgumentParseResult.SuccessfullParse));
                }
            }

            if (context.Arguments.TotalCount == 2)
            {
                return(Task.FromResult(new ArgumentParseResult(Arguments[2], "Cannot assign an empty value!")));
            }

            if (!Enum.TryParse(context.Arguments.First, true, out assignType))
            {
                return(Task.FromResult(new ArgumentParseResult(Arguments[1])));
            }

            if (assignType == BotVarType.Undefined)
            {
                return(Task.FromResult(new ArgumentParseResult(Arguments[1])));
            }

            context.Arguments.Index++;

            value = context.Arguments.First;

            switch (assignType)
            {
            case BotVarType.UInt64:
                if (ulong.TryParse(value, out ulong uint64Val))
                {
                    BotVar = new BotVar(BotVarId, uint64Val);
                }
                else
                {
                    return(Task.FromResult(new ArgumentParseResult(Arguments[2])));
                }
                break;

            case BotVarType.Int64:
                if (long.TryParse(value, out long int64Val))
                {
                    BotVar = new BotVar(BotVarId, int64Val);
                }
                else
                {
                    return(Task.FromResult(new ArgumentParseResult(Arguments[2])));
                }
                break;

            case BotVarType.Float64:
                if (double.TryParse(value, out double float64Val))
                {
                    BotVar = new BotVar(BotVarId, float64Val);
                }
                else
                {
                    return(Task.FromResult(new ArgumentParseResult(Arguments[2])));
                }
                break;

            case BotVarType.String:
                BotVar = new BotVar(BotVarId, value);
                break;

            case BotVarType.Bool:
                if (bool.TryParse(value, out bool boolVal))
                {
                    BotVar = new BotVar(BotVarId, boolVal);
                }
                else
                {
                    return(Task.FromResult(new ArgumentParseResult(Arguments[2])));
                }
                break;

            case BotVarType.Generic:
                if (JSONContainer.TryParse(value, out JSONContainer json, out string error))
                {
                    BotVar = new BotVar(BotVarId, json);
                }
                else
                {
                    return(Task.FromResult(new ArgumentParseResult(Arguments[2], error)));
                }
                break;
예제 #11
0
 internal static void OnBotVarSetup()
 {
     BotVarManager.SubscribeToBotVarUpdateEvent(OnBotVarUpdated, "inara_appname", "inara_apikey");
 }
예제 #12
0
 public static void OnBotVarSetup()
 {
     BotVarManager.SubscribeToBotVarUpdateEvent(OnBotVarUpdated, "storedmsgsprefix");
 }
예제 #13
0
 public StoredMessagesService(ulong guildId)
 {
     guildBotVars = BotVarManager.GetGuildBotVarCollection(guildId);
 }
예제 #14
0
        protected override Task <ArgumentParseResult> ParseArguments(IDMCommandContext context)
        {
            ArgumentContainer argOut = new ArgumentContainer();

            // Parse <Context> argument
            if (context.Arguments.First.ToLower() == "save")
            {
                argOut.mode = CommandMode.save;
                return(Task.FromResult(new ArgumentParseResult(argOut)));
            }
            else if (context.Arguments.First.ToLower() == "global")
            {
                argOut.TargetBotVarCollection = BotVarManager.GlobalBotVars;
            }
            else
            {
                if (!ArgumentParsing.TryParseGuild(context, context.Arguments.First, out SocketGuild guild))
                {
                    return(Task.FromResult(new ArgumentParseResult(Arguments[0])));
                }
                argOut.TargetBotVarCollection = BotVarManager.GetGuildBotVarCollection(guild.Id);
            }

            context.Arguments.Index++;

            if (context.Arguments.TotalCount == 1) // If argcnt is 1 (only context provided), commandmode is to list all botvars
            {
                argOut.mode = CommandMode.list;
                return(Task.FromResult(new ArgumentParseResult(argOut)));
            }

            // Parse <BotVar Id> argument

            argOut.BotVarId = context.Arguments.First;
            argOut.TargetBotVarCollection.TryGetBotVar(argOut.BotVarId, out argOut.BotVar);

            if (context.Arguments.TotalCount == 2) // If argcnt is 2 (only context and BotVar id provided), commandmode is to display the requested botvar
            {
                argOut.mode = CommandMode.get;
                if (argOut.BotVar.IsDefined)
                {
                    return(Task.FromResult(new ArgumentParseResult(argOut)));
                }
                else
                {
                    return(Task.FromResult(new ArgumentParseResult(Arguments[0], $"Couldn't locate a config variable named `{argOut.BotVarId}`!")));
                }
            }

            context.Arguments.Index++;

            // Parse argument <Type>

            if (!parseArgument_Type(context, argOut, out ArgumentParseResult failedTypeArgParse))
            {
                return(Task.FromResult(failedTypeArgParse));
            }

            if (argOut.mode == CommandMode.delete) // No further parsing required as mode is delete
            {
                return(Task.FromResult(new ArgumentParseResult(argOut)));
            }

            if (context.Arguments.TotalCount == 3) // No value argument provided
            {
                return(Task.FromResult(new ArgumentParseResult(Arguments[2], "Cannot assign an empty value!")));
            }

            context.Arguments.Index++;

            // Parse value argument
            if (!parseArgument_Value(context, argOut, out ArgumentParseResult failedValueArgParse))
            {
                return(Task.FromResult(failedValueArgParse));
            }

            return(Task.FromResult(new ArgumentParseResult(argOut)));
        }
예제 #15
0
 public void OnBotVarSetup()
 {
     BotVarManager.SubscribeToBotVarUpdateEvent(OnBotVarUpdate, "prefix");
 }