public static async Task CreateSettings(SocketGuild guild) { try { using (var connection = new SqliteConnection(DbPath)) { await connection.OpenAsync(); var possibleEntry = await connection.ExecuteScalarAsync <ulong>("select Id from GuildSettings where Id = @Id", new { Id = guild.Id }); if (possibleEntry == 0) { var setting = new GuildSetting { Id = guild.Id, Prefix = DefaultPrefix, IsMinimal = false, GuessChannelsString = "0", }; await connection.InsertAsync(setting); _guildSettings[guild.Id] = setting; } connection.Close(); } }catch (Exception e) { Console.WriteLine(e.StackTrace); } }
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); }
public async Task <GuildSetting> SaveGuildSetting(ulong guildId, string key, string value) { var setting = await _dbContext.GuildSettings .SingleOrDefaultAsync(gs => gs.GuildId == guildId && gs.Key == key); if (setting == null) { setting = new GuildSetting() { GuildId = guildId, Key = key, Value = value }; await _dbContext.AddAsync(setting); } else { setting.Value = value; } await _dbContext.SaveChangesAsync(); return(setting); }
public static bool IsAdminOrHigher(ulong Id, IGuild Guild, GuildSetting Settings) { var res = IsAdmin(Id, Settings) || IsServerOwner(Id, Guild) || IsGlobalAdmin(Id) || IsOwner(Id); return(res); }
public static bool IsNsfwChannel(GuildSetting GuildSettings, ulong ChannelId) { if (GuildSettings.NsfwChannels.Contains(ChannelId)) { return(true); } if (Client.GetChannel(ChannelId) is ITextChannel Channel) { return(Channel.IsNsfw); } return(false); }
public GuildSetting GetSettings(ulong GuildId) { if (!Settings.TryGetValue(GuildId, out GuildSetting Setting)) { Setting = new GuildSetting() { GuildId = GuildId }; Settings.Add(GuildId, Setting); Save(); } return(Setting); }
public void NewSetup(IGuild guild) { using (var db = new LiteDatabase("./guilds.db")) { var serverdb = db.GetCollection <GuildSetting>("guildsettings"); var guildentry = new GuildSetting { guildName = guild.Name, isSetup = true }; serverdb.Insert(guildentry); serverdb.EnsureIndex(x => x.guildName); } }
public static List <ulong> Blocked(ulong Id = 0) { GuildSetting Setting = null; if (Id != 0) { Setting = Id.GetSettings(); } if (Setting != null) { return(Setting.Blocked.Select(t => t.Id).ToList()); } else { return(Settings.GloballyBlocked.Select(t => t.Id).ToList()); } }
public static UserAccess GetUserAccess(ulong UserId, GuildSetting Settings, ulong GuildId) { if (UserId == Global.Settings.OwnerId) { return(UserAccess.Owner); } else if (Global.IsGlobalAdmin(UserId)) { return(UserAccess.GlobalAdmin); } else if (Global.Client.GetGuild(GuildId).OwnerId == UserId) { return(UserAccess.ServerOwner); } else if (Settings.AdminIds.Contains(UserId)) { return(UserAccess.Admin); } return(UserAccess.Common); }
public static bool IsBlocked(ulong Id, ulong GuildOrDMId = 0) { GuildSetting Setting = null; if (GuildOrDMId != 0) { Setting = GuildOrDMId.GetSettings(); } if (Setting != null) { var Index = Setting.Blocked.FindIndex(p => p.Id == Id); if (Index < 0) { Index = Settings.GloballyBlocked.FindIndex(p => p.Id == Id); } return(Index > -1); } else { var Index = Settings.GloballyBlocked.FindIndex(p => p.Id == Id); return(Index > -1); } }
public GatewayUserGuildSettingsUpdatedMessage(GuildSetting settings) { Settings = settings; }
public LevelSystem(DiscordSocketClient Client) { Levels = new List <uint>() { 100 }; Users = new UserHandler(this); Client.MessageReceived += async(Message) => { if (!(Message is SocketUserMessage sMessage)) { return; } ICommandContext Context = new SocketCommandContext(Global.Client, sMessage); if (Context.Guild == null || Message.Author.IsBot) { return; } GuildSetting Settings = Context.Guild.GetSettings(); LanguageEntry Language = Settings.GetLanguage(); if (!Settings.Leveling) { return; } if (Settings.LevelingAvoidChannel.Contains(Context.Channel.Id)) { return; } if (Settings.LevelingWatchExtensions.Count != 0) { if (Message.Attachments.Count == 0) { return; } foreach (IAttachment Attachment in Message.Attachments) { if (!Settings.LevelingWatchExtensions.Contains(Attachment.Url.Split('.').Last().ToLower())) { return; } } } User User; if (Users.ContainsKey(Message.Author.Id)) { User = Users[Message.Author.Id]; } else { User = new User() { UserId = Message.Author.Id }; } uint Xp = Global.Random.NextUInt(5, 7); uint LengthBonus = (uint)(Message.Content.Length / 40); if (LengthBonus > 5) { LengthBonus = 5; } Xp += LengthBonus; if (!User.GuildXps.ContainsKey(Context.Guild.Id)) { User.GuildXps.Add(Context.Guild.Id, Xp); User.GuildLevels.Add(Context.Guild.Id, 0); } else { User.GuildXps[Context.Guild.Id] += Xp; } uint NextLevelExp = Levels[(int)User.GuildLevels[Context.Guild.Id]]; if (User.GuildXps[Context.Guild.Id] > NextLevelExp) { User.GuildLevels[Context.Guild.Id]++; if (Levels.Count - 1 <= User.GuildLevels[Context.Guild.Id]) { GenerateLevel(1); } IGuildUser gUser = Context.User as IGuildUser; string Prefix = Context.Guild.GetSettings().Prefix; IMessageChannel Channel = Message.Channel; if (Settings.LevelupReport != 0) { ITextChannel ReportChannel = await Context.Guild.GetTextChannelAsync(Settings.LevelupReport); if (ReportChannel != null) { Channel = ReportChannel; } } EmbedBuilder Embed = new EmbedBuilder() { Author = new EmbedAuthorBuilder() { Name = gUser.Nickname ?? gUser.Username, IconUrl = gUser.GetAvatarUrl() }, Description = Language.GetEntry("LevelSystem:Congratulation", "USER", gUser.Nickname ?? gUser.Username, "LEVEL", User.GuildLevels[Context.Guild.Id] + ""), Footer = new EmbedFooterBuilder() { Text = Language.GetEntry("LevelSystem:LevelFooter", "PREFIX", Prefix) }, Color = Color.DarkPurple }; try { await Channel.SendMessageAsync("", embed : Embed.Build()); } catch { } // Couldn't send the message, doesn't have permission or sth like that if (Settings.AssignRoleAtLevels.ContainsKey(User.GuildLevels[Context.Guild.Id])) { List <ulong> RoleIds = Settings.AssignRoleAtLevels[User.GuildLevels[Context.Guild.Id]]; foreach (ulong RoleId in RoleIds) { if (Context.Guild.GetRole(RoleId) is IRole Role) { if (!gUser.RoleIds.Contains(RoleId)) { await gUser.AddRoleAsync(Role); } } } } } Users.UpdateUser(User); }; }
public static LanguageEntry GetLanguage(this GuildSetting Settings) { return(Global.Languages.GetLanguage(Settings.Language)); }
public OliveGuild(ulong id) { GuildId = id; Setting = new GuildSetting(); Levels = new Dictionary <string, UserLevel>(); }
public static bool IsAdmin(ulong Id, GuildSetting Settings) { return(Settings.Admins.Select(t => t.Id).Contains(Id)); }
/// <inheritdoc /> public virtual Task <GuildSetting> ModifyGuildSettings(string guildId, GuildSetting guildSetting) { var arguments = new object[] { guildId, guildSetting }; return((Task <GuildSetting>)methodImpls["ModifyGuildSettings"](Client, arguments)); }
/// <summary> /// Initializes a new instance of the <see cref="BindableGuild"/> class. /// </summary> /// <param name="model">The base <see cref="Guild"/> object.</param> public BindableGuild([NotNull] Guild model) : base(model) { _channels = new ObservableCollection <BindableChannel>(); MessengerInstance.Register <GatewayGuildUpdatedMessage>(this, m => { if (m.Guild.Id == Model.Id) { DispatcherHelper.CheckBeginInvokeOnUi(() => { Model = m.Guild; RaisePropertyChanged(nameof(DisplayText)); RaisePropertyChanged(nameof(HasIcon)); RaisePropertyChanged(nameof(IconUrl)); }); } }); MessengerInstance.Register <GatewayMessageRecievedMessage>(this, m => { DispatcherHelper.CheckBeginInvokeOnUi(() => { RaisePropertyChanged(nameof(NotificationCount)); RaisePropertyChanged(nameof(IsUnread)); RaisePropertyChanged(nameof(ShowUnread)); }); }); MessengerInstance.Register <GatewayMessageAckMessage>(this, m => { DispatcherHelper.CheckBeginInvokeOnUi(() => { RaisePropertyChanged(nameof(NotificationCount)); RaisePropertyChanged(nameof(IsUnread)); RaisePropertyChanged(nameof(ShowUnread)); }); }); MessengerInstance.Register <GatewayUserGuildSettingsUpdatedMessage>(this, m => { if ((m.Settings.GuildId ?? "DM") == Model.Id) { DispatcherHelper.CheckBeginInvokeOnUi(() => { GuildSetting guildSetting = GuildsService.GetGuildSetting(Model.Id); if (guildSetting != null) { IsMuted = guildSetting.Muted; } }); } }); MessengerInstance.Register <SettingChangedMessage <bool> >(this, m => { if (m.Key == SettingKeys.ServerMuteIcons) { RaisePropertyChanged(nameof(ShowMute)); } }); }
public void Update(GuildSetting Setting) { Settings[Setting.GuildId] = Setting; Save(); }