Ejemplo n.º 1
0
        private static Task SubscribeEventLoggerSettingsBotVar(SocketGuild guild)
        {
            BotVarCollection collection = BotVarManager.GetGuildBotVarCollection(guild.Id);

            collection.SubscribeToBotVarUpdateEvent(EventLogger.OnBotVarUpdatedGuild, "logChannels");
            return(Task.CompletedTask);
        }
Ejemplo n.º 2
0
        public override bool PreconditionCheckGuild(IGuildCommandContext context, out string message)
        {
            BotVarCollection 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);
        }
        public static GuildChannelMeta GetDefaultOrSaved(ulong guildId, ulong channelId)
        {
            BotVarCollection guildBotVarCollection = BotVarManager.GetGuildBotVarCollection(guildId);

            if (!guildBotVarCollection.TryGetBotVar($"{channelId}.meta", out GuildChannelMeta channelMeta))
            {
                channelMeta = GetDefault(guildId);
            }
            return(channelMeta);
        }
 internal static void SubscribeToBotVarCollection(BotVarCollection botVarCollection)
 {
     if (botVarCollection != BotVarManager.GlobalBotVars)
     {
         botVarCollection.SubscribeToBotVarUpdateEvent(OnBotVarUpdatedGuild, "logChannels");
         if (botVarCollection.TryGetBotVar("logChannels", out EventLoggerSettings settings))
         {
             GuildEventLoggerSettings[botVarCollection.GuildID] = settings;
         }
     }
 }
Ejemplo n.º 5
0
        private static void SetupBotVarDefaults()
        {
            BotVar defaultColor = new BotVar("embedcolor", new ColorBotVar(new Color(255, 255, 255)));

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

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

            OnBotVarDefaultSetup?.Invoke();
        }
 public static GuildChannelMeta GetDefault(ulong guildId)
 {
     if (!guildDefaults.TryGetValue(guildId, out GuildChannelMeta guildDefault))
     {
         BotVarCollection guildBotVarCollection = BotVarManager.GetGuildBotVarCollection(guildId);
         if (!guildBotVarCollection.TryGetBotVar("defaultguildchannelmeta", out guildDefault))
         {
             guildDefault = new GuildChannelMeta();
         }
         guildDefaults.Add(guildId, guildDefault);
         guildBotVarCollection.SubscribeToBotVarUpdateEvent(OnBotVarUpdated, "defaultguildchannelmeta");
     }
     return(guildDefault);
 }
        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);
            }
        }
 public StoredMessagesService(ulong guildId)
 {
     guildBotVars = BotVarManager.GetGuildBotVarCollection(guildId);
 }