Exemple #1
0
        public void ReloadConfig(string dbConnectionString)
        {
            this.DbConnectionString = dbConnectionString;
            ServerContext dbContext = ServerContext.Create(dbConnectionString);

            this.Config = dbContext.ServerConfigurations.FirstOrDefault(c => c.ServerId == this.Id);
            if (this.Config == null)
            {
                this.Config = new ServerConfig()
                {
                    ServerId = this.Id, Name = this.Guild.Name
                };
                dbContext.ServerConfigurations.Add(this.Config);
            }

            this.CustomCommands?.Clear();
            this.CustomAliases?.Clear();
            this.Roles?.Clear();

            this.CustomCommands = dbContext.CustomCommands.Where(c => c.ServerId == this.Id).ToDictionary(c => c.CommandId);
            this.CustomAliases  = dbContext.CustomAliases.Where(c => c.ServerId == this.Id).ToDictionary(c => c.Alias);
            this.Roles          = dbContext.Roles.Where(c => c.ServerId == this.Id).ToDictionary(c => c.RoleId);
        }
Exemple #2
0
        public string GetWhoisString(ServerContext dbContext, SocketGuildUser user = null)
        {
            StringBuilder whoisString = new StringBuilder();

            if (user != null)
            {
                whoisString.AppendLine($"<@{this.UserId}>: `{this.UserId}` | `{user.GetUsername()}`\n" +
                                       $"    Account created at: {Utils.GetTimestamp(Utils.GetTimeFromId(this.UserId))}");
            }
            else
            {
                whoisString.AppendLine($"<@{this.UserId}>: `{this.UserId}`\n" +
                                       $"    Account created at: {Utils.GetTimestamp(Utils.GetTimeFromId(this.UserId))}");
            }

            if (user?.JoinedAt != null)
            {
                whoisString.AppendLine("    Joined the server: " + Utils.GetTimestamp(user.JoinedAt.Value));
            }

            if (user != null)
            {
                whoisString.AppendLine("    Roles: " + user.Roles.Select(r => r.Name.Replace('`', '\'')).ToNames());
            }

            if (this.Verified)
            {
                whoisString.AppendLine("    Verified: `true`");
            }

            if (this.Ignored)
            {
                whoisString.AppendLine("    Ignored by Logging: `true`");
            }

            if (this.MutedUntil > DateTime.UtcNow)
            {
                whoisString.AppendLine("    Muted until: " + Utils.GetTimestamp(this.MutedUntil));
            }

            if (this.BannedUntil > DateTime.UtcNow)
            {
                whoisString.AppendLine("    Banned until: " + Utils.GetTimestamp(this.BannedUntil));
            }

            List <string> foundUsernames = dbContext.Usernames
                                           .Where(u => u.ServerId == this.ServerId && u.UserId == this.UserId)
                                           .Select(u => u.Name.Replace('`', '\'')).ToList();

            whoisString.Append("    Known usernames: ");
            whoisString.AppendLine(foundUsernames.ToNames());

            List <string> foundNicknames = dbContext.Nicknames
                                           .Where(u => u.ServerId == this.ServerId && u.UserId == this.UserId)
                                           .Select(u => u.Name.Replace('`', '\'')).ToList();

            whoisString.Append("    Known nicknames: ");
            whoisString.AppendLine(foundNicknames.ToNames());

            if (this.WarningCount > 0 || !string.IsNullOrEmpty(this.Notes))
            {
                whoisString.AppendLine($"They have {this.WarningCount} warnings, with these notes: {this.Notes}");
            }

            return(whoisString.ToString().Replace("@everyone", "@-everyone").Replace("@here", "@-here"));
        }
Exemple #3
0
 public void LoadConfig(string dbConnectionString, ServerContext dbContext, Dictionary <string, Command> allCommands)
 {
     ReloadConfig(dbConnectionString, dbContext, allCommands);
 }
Exemple #4
0
 public void LoadConfig(string dbConnectionString, ServerContext dbContext)
 {
     ReloadConfig(dbConnectionString, dbContext);
 }