Exemplo n.º 1
0
        public async Task <ITextChannel> GetChannel(Discord.IGuild guild, string eventName = null)
        {
            if (eventName == null)
            {
                return(null);
            }

            FloofDataContext _floofDb = new FloofDataContext();

            var serverConfig = _floofDb.LogConfigs.Find(guild.Id);

            System.Reflection.PropertyInfo propertyInfo = serverConfig.GetType().GetProperty(eventName);
            ulong logChannel  = (ulong)(propertyInfo.GetValue(serverConfig, null));
            var   textChannel = await guild.GetTextChannelAsync(logChannel);

            return(textChannel);
        }
Exemplo n.º 2
0
            private bool TryLinkChannelType(string channelType, Discord.IChannel channel, Discord.IGuild guild)
            {
                ulong serverId  = guild.Id;
                ulong channelId = channel == null ? 0 : channel.Id;

                AddServerIfNotExists(serverId);
                try
                {
                    string updateCommand = $"UPDATE LogConfigs SET {channelType} = {channelId} WHERE ServerID = {serverId}";
                    _floofDB.Database.ExecuteSqlRaw(updateCommand);
                    _floofDB.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    string errorMsg = $"Error: Unable to link {channelType} to <#{channelId}>";
                    Log.Error(errorMsg + Environment.NewLine + e);
                    return(false);
                }
            }
Exemplo n.º 3
0
        public static string Prepare(this string Trivia, Dictionary <string, string> Changes, ITextChannel Channel = null, Discord.IGuild Guild = null, Discord.IUser User = null)
        {
            var changes = new Dictionary <string, string>(Changes)
            {
                { "%OWNER%", Global.Settings.OwnerName }
            };

            GuildSetting Settings = null;

            if (Channel != null && Settings == null)
            {
                Settings = Channel.GetSettings();
            }
            else if (Guild != null && Settings == null)
            {
                Settings = Guild.GetSettings();
            }
            else if (User != null && Settings == null)
            {
                Settings = Global.GuildSettings.GetSettings(User.Id);
            }

            if (User != null)
            {
                changes.Add("%MENTION%", User.Mention);
            }

            if (Settings != null)
            {
                changes.Add("%P%", Settings.Prefix);
                changes.Add("%PREFIX%", Settings.Prefix);
            }

            var Text = Trivia;

            if (Text.Contains("%LANGUAGES%") || Text.Contains("%LANGS%"))
            {
                var LangNames = string.Join(", ", Global.LanguageHandler.Languages.Select(langPair => langPair.Key + " - " + langPair.Value.Name));
                Text = Text.Replace("%LANGUAGES%", LangNames);
                Text = Text.Replace("%LANGS%", LangNames);
            }

            foreach (var Pair in changes)
            {
                string Key = Pair.Key;

                if (!Key.EndsWith("%"))
                {
                    Key += "%";
                }
                if (!Key.StartsWith("%"))
                {
                    Key = "%" + Key;
                }

                Text = Text.Replace(Key.ToUpper(), Pair.Value);
            }

            return(Text);
        }