public async Task SetAFK([Remainder] string status) { if (string.IsNullOrEmpty(status)) { await Context.Message.ReplyAsync("", false, Global.EmbedMessage("Error", "Please enter a valid AFK status.", false, Color.Red).Build()); return; } MongoClient mongoClient = new MongoClient(Global.Mongoconnstr); IMongoDatabase database = mongoClient.GetDatabase("finlay"); IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>("guilds"); ulong _id = Context.Guild.Id; BsonDocument guildDocument = await MongoHandler.FindById(collection, _id); if (guildDocument == null) { MongoHandler.InsertGuild(_id); } BsonDocument guild = await collection.Find(Builders <BsonDocument> .Filter.Eq("_id", _id)).FirstOrDefaultAsync(); if (guild == null) { //BsonDocument statusDocument = new BsonDocument { { "_id", (decimal)_id }, { "AFKUsers", new BsonArray { new BsonDocument { { Context.Message.Author.Id.ToString(), status } } } } }; BsonDocument statusDocument = new BsonDocument { { "_id", (decimal)_id }, { "AFKUsers", /*new BsonArray {*/ new BsonDocument { { Context.Message.Author.Id.ToString(), status } } } /*} */ }; collection.InsertOne(statusDocument); } else { BsonDocument test = new BsonDocument { { "$push", new BsonDocument { { "AFKUsers", new BsonDocument { { Context.Message.Author.Id.ToString(), status } } } } } }; BsonDocument testing = new BsonDocument { { "_id", (decimal)_id } }; collection.UpdateOne(testing, test); } await Context.Message.ReplyAsync($"Successfully set AFK status to: {status}"); try { SocketGuildUser user = (SocketGuildUser)Context.Message.Author; if (user.Nickname != null) { await user.ModifyAsync(x => { x.Nickname = $"[AFK] {user.Nickname}"; }); } else { await user.ModifyAsync(x => { x.Nickname = $"[AFK] {user.Username}"; }); } } catch { } }
public async Task SetWelcomeChannel([Remainder] SocketChannel channel) { SocketGuildUser GuildUser = Context.Guild.GetUser(Context.User.Id); if (GuildUser.GuildPermissions.ManageChannels || Global.DevUIDs.Contains(Context.Message.Author.Id)) { if (channel.GetType() == typeof(SocketVoiceChannel)) { EmbedBuilder eb = new EmbedBuilder(); eb.WithTitle("Error setting welcome channel"); eb.WithDescription($"The welcome channel type must be a text channel!"); eb.WithColor(Color.Red); eb.WithAuthor(Context.Message.Author); eb.WithCurrentTimestamp(); await Context.Message.ReplyAsync("", false, eb.Build()); return; } MongoClient mongoClient = new MongoClient(Global.Mongoconnstr); IMongoDatabase database = mongoClient.GetDatabase("finlay"); IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>("guilds"); ulong _id = Context.Guild.Id; BsonDocument guildDocument = await MongoHandler.FindById(collection, _id); if (guildDocument == null) { MongoHandler.InsertGuild(_id); } BsonDocument guild = await collection.Find(Builders <BsonDocument> .Filter.Eq("_id", _id)).FirstOrDefaultAsync(); ulong _chanId = channel.Id; if (guild == null) { BsonDocument document = new BsonDocument { { "_id", (decimal)_id }, { "welcomechannel", (decimal)_chanId } }; collection.InsertOne(document); } else { collection.UpdateOne(Builders <BsonDocument> .Filter.Eq("_id", _id), Builders <BsonDocument> .Update.Set("welcomechannel", _chanId)); } EmbedBuilder embed = new EmbedBuilder(); embed.WithTitle("Success"); embed.WithDescription($"Successfully set the welcome channel to <#{_chanId}>!"); embed.WithColor(Color.Green); embed.WithAuthor(Context.Message.Author); embed.WithCurrentTimestamp(); await Context.Message.ReplyAsync("", false, embed.Build()); } else { await Context.Channel.TriggerTypingAsync(); await Context.Message.Channel.SendMessageAsync("", false, new EmbedBuilder() { Color = Color.LightOrange, Title = "You don't have Permission!", Description = $"Sorry, {Context.Message.Author.Mention} but you do not have permission to use this command.", Author = new EmbedAuthorBuilder() { Name = Context.Message.Author.ToString(), IconUrl = Context.Message.Author.GetAvatarUrl() ?? Context.User.GetDefaultAvatarUrl(), Url = Context.Message.GetJumpUrl() } }.Build()); } }
public async Task EnableLevelling([Remainder] string toggle) { SocketGuildUser GuildUser = Context.Guild.GetUser(Context.User.Id); if (GuildUser.GuildPermissions.Administrator || Global.DevUIDs.Contains(Context.Message.Author.Id)) { bool enabled = false; if (toggle == "true" || toggle == "on") { enabled = true; } MongoClient mongoClient = new MongoClient(Global.Mongoconnstr); IMongoDatabase database = mongoClient.GetDatabase("finlay"); IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>("guilds"); ulong _id = Context.Guild.Id; BsonDocument guildDocument = await MongoHandler.FindById(collection, _id); if (guildDocument == null) { MongoHandler.InsertGuild(_id); } BsonDocument guild = await collection.Find(Builders <BsonDocument> .Filter.Eq("_id", _id)).FirstOrDefaultAsync(); if (guild == null) { BsonDocument document = new BsonDocument { { "_id", (decimal)_id }, { "levelling", enabled } }; collection.InsertOne(document); } else { collection.UpdateOne(Builders <BsonDocument> .Filter.Eq("_id", _id), Builders <BsonDocument> .Update.Set("levelling", enabled)); } EmbedBuilder embed = new EmbedBuilder(); embed.WithTitle("Success"); embed.WithDescription($"Successfully set levelling to {enabled}!"); embed.WithColor(Color.Green); embed.WithAuthor(Context.Message.Author); embed.WithCurrentTimestamp(); await Context.Message.ReplyAsync("", false, embed.Build()); } else { await Context.Channel.TriggerTypingAsync(); await Context.Message.Channel.SendMessageAsync("", false, new EmbedBuilder() { Color = Color.LightOrange, Title = "You don't have Permission!", Description = $"Sorry, {Context.Message.Author.Mention} but you do not have permission to use this command.", Footer = new EmbedFooterBuilder() { IconUrl = Context.User.GetAvatarUrl() ?? Context.User.GetDefaultAvatarUrl(), Text = $"{Context.User}" }, }.WithCurrentTimestamp().Build()); } }
public async Task NotifyTwitch(string user) { SocketGuildUser GuildUser = Context.Guild.GetUser(Context.User.Id); if (GuildUser.GuildPermissions.ManageMessages || Global.DevUIDs.Contains(Context.Message.Author.Id)) { List <TwitchHandler.TwitchData> ValidateUser = await TwitchHandler.GetTwitchInfo(user); if (ValidateUser.Count == 0) { await Context.Message.ReplyAsync("", false, Global.EmbedMessage("Error", $"The user {user} could not be found on Twitch.", false, Color.Red).Build()); return; } MongoClient mongoClient = new MongoClient(Global.Mongoconnstr); IMongoDatabase database = mongoClient.GetDatabase("finlay"); IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>("guilds"); ulong _id = Context.Guild.Id; BsonDocument guildDocument = await MongoHandler.FindById(collection, _id); if (guildDocument == null) { MongoHandler.InsertGuild(_id); } BsonDocument guild = await collection.Find(Builders <BsonDocument> .Filter.Eq("_id", _id)).FirstOrDefaultAsync(); try { string itemVal = guild?.GetValue("TwitchUsers").ToJson(); List <string> stringArray = JsonConvert.DeserializeObject <string[]>(itemVal).ToList(); Regex re = new Regex(@"\b(" + string.Join("|", stringArray.Select(word => string.Join(@"\s*", word.ToCharArray()))) + @")\b", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace); if (re.IsMatch(user)) { EmbedBuilder errembed = new EmbedBuilder(); errembed.WithTitle("Error"); errembed.WithDescription("This user is already included in the notification list!"); errembed.WithColor(Color.Red); errembed.WithAuthor(Context.Message.Author); await Context.Message.ReplyAsync("", false, errembed.Build()); return; } } catch { } if (guild == null) { BsonDocument document = new BsonDocument { { "_id", (decimal)_id }, { "TwitchUsers", user } }; collection.InsertOne(document); } else { collection.UpdateOne(Builders <BsonDocument> .Filter.Eq("_id", _id), Builders <BsonDocument> .Update.Push("TwitchUsers", user)); } EmbedBuilder embed = new EmbedBuilder(); embed.WithTitle("Twitch notification user list updated!"); embed.WithDescription($"Successfully added notifications for when {user} goes live on Twitch!"); embed.WithColor(Color.Green); embed.WithAuthor(Context.Message.Author); embed.WithCurrentTimestamp(); await Context.Message.Channel.SendMessageAsync("", false, embed.Build()); } else { await Context.Channel.TriggerTypingAsync(); await Context.Message.Channel.SendMessageAsync("", false, new EmbedBuilder() { Color = Color.LightOrange, Title = "You don't have Permission!", Description = $"Sorry, {Context.Message.Author.Mention} but you do not have permission to use this command.", Footer = new EmbedFooterBuilder() { IconUrl = Context.User.GetAvatarUrl() ?? Context.User.GetDefaultAvatarUrl(), Text = $"{Context.User}" }, }.WithCurrentTimestamp().Build()); } }
public async Task prefix([Remainder] string new_prefix) { SocketGuildUser GuildUser = Context.Guild.GetUser(Context.User.Id); if (GuildUser.GuildPermissions.Administrator || Global.DevUIDs.Contains(Context.Message.Author.Id)) { MongoClient mongoClient = new MongoClient(Global.Mongoconnstr); IMongoDatabase database = mongoClient.GetDatabase("finlay"); IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>("guilds"); ulong _id = Context.Guild.Id; BsonDocument guildDocument = await MongoHandler.FindById(collection, _id); if (guildDocument == null) { MongoHandler.InsertGuild(_id); } BsonDocument guild = await collection.Find(Builders <BsonDocument> .Filter.Eq("_id", _id)).FirstOrDefaultAsync(); if (guild == null) { BsonDocument document = new BsonDocument { { "_id", (decimal)_id }, { "prefix", new_prefix } }; collection.InsertOne(document); Global.UpdatePrefix(_id, new_prefix, await Global.DeterminePrefix(Context)); } else { collection.UpdateOne(Builders <BsonDocument> .Filter.Eq("_id", _id), Builders <BsonDocument> .Update.Set("prefix", new_prefix)); Global.UpdatePrefix(_id, new_prefix, await Global.DeterminePrefix(Context)); } EmbedBuilder embed = new EmbedBuilder(); embed.WithTitle("Prefix updated!"); embed.WithDescription($"Set the prefix for this guild to: {new_prefix}"); embed.WithColor(Color.Green); embed.WithAuthor(Context.Message.Author); embed.WithCurrentTimestamp(); await Context.Message.ReplyAsync("", false, embed.Build()); } else { await Context.Channel.TriggerTypingAsync(); await Context.Message.Channel.SendMessageAsync("", false, new EmbedBuilder() { Color = Color.LightOrange, Title = "You don't have Permission!", Description = $"Sorry, {Context.Message.Author.Mention} but you do not have permission to use this command.", Author = new EmbedAuthorBuilder() { Name = Context.Message.Author.ToString(), IconUrl = Context.Message.Author.GetAvatarUrl() ?? Context.User.GetDefaultAvatarUrl(), Url = Context.Message.GetJumpUrl() } }.Build()); } }