//Posts whenever user changes name, not nickname private async Task UserUpdated(SocketUser user, SocketUser user2) { EmbedBuilder embed = new EmbedBuilder(); if (user.ToString().Equals(user2.ToString())) { return; } embed.WithTitle($"{user.ToString()} has changed their name.") .WithColor(Color.Magenta); embed.AddField("Updates", $"From `{user.ToString()}` to `{user2.ToString()}`\n ID: {user.Id}"); foreach (var guild in _client.Guilds) { if (guild.Users.Contains(user2)) { var channelId = Logging.getLogChannel(guild.Id); if (channelId == 0) { continue; } //channel id isn't empty var channel = _client.GetChannel(channelId) as IMessageChannel; await channel.SendMessageAsync("", false, embed.Build()); } } }
public static async Task <Embed> CreateModlog(SocketGuild guild, SocketUser caller, SocketUser user, ModlogType type, string Reason = null) { var guildObj = FileSystem.GetGuild(guild); if (!guildObj.AllowModlog) { throw new Exception("Modlog isn't enabled on this server\nUse //setmodlogchannel to enable modlog"); } var embed = new EmbedBuilder(); Embed Result = null; switch (type) { case ModlogType.Ban: Result = embed .WithColor(Color.Red) .WithCurrentTimestamp() .WithTitle($"[#{guildObj.ModlogCount + 1}] {caller.ToString()} banned {user.ToString()} from the server") .WithDescription($"**Reason:** {Reason ?? "No reason given"}") .Build(); break; case ModlogType.Kick: Result = embed .WithColor(Color.Orange) .WithCurrentTimestamp() .WithTitle($"[#{guildObj.ModlogCount + 1}] {caller.ToString()} kicked {user.ToString()} from the server") .WithDescription($"**Reason:** {Reason ?? "No reason given"}") .Build(); break; case ModlogType.Muted: Result = embed .WithColor(Color.Purple) .WithCurrentTimestamp() .WithTitle($"[#{guildObj.ModlogCount + 1}] {caller.ToString()} muted {user.ToString()}") .WithDescription($"**Reason:** {Reason ?? "No reason given"}") .Build(); break; case ModlogType.Warn: var guilduser = guildObj.GuildUsers.Where(x => x.ID == user.Id).First(); guilduser = guilduser.IncreaseWarnCount(); guildObj.SetGuildUser(guilduser); Result = embed .WithColor(Color.Gold) .WithCurrentTimestamp() .WithTitle($"[#{guildObj.ModlogCount + 1}] {caller.ToString()} warned {user.ToString()}") .WithDescription($"{user.Username} has a total of {guilduser.WarnCount} now\n**Reason:** {Reason ?? "No reason given"}") .Build(); break; } guildObj = guildObj.IncreaseModlogCount(); await FileSystem.SetGuild(guildObj); return(Result); }
public static async void AddXpAndCheckLevel(SocketUser user, SocketGuild guild, uint xp) { var account = UserAccounts.GetAccount(user); string userString = user.ToString(); if (userString != "Mord#1715" || userString != "Grumpy cat#6522") { if (account.XP >= 100) { while (account.XP >= 100) { account.XP -= 100; account.Level += 1; } try { await guild.DefaultChannel.SendMessageAsync($":tada: {user.Mention} is now level {account.Level} use: `?level` to see more :tada:"); } catch (Exception e) { Console.WriteLine(String.Format("{0:G}", DateTime.Now) + $" *********** couldn't send a message to the default channel ***********"); } } AddXp(user, xp); } }
public static void CreateUserInDatabase(SocketUser userName) { var user = userName as SocketGuildUser; var date = user.JoinedAt.ToString(); var document = new BsonDocument { { "_id", (long)user.Id }, { "name", userName.ToString() }, { "dateJoined", date }, { "numberOfMessages", 0 }, { "isBetaTester", false }, { "reactionCount", 0 }, { "experience", 0 }, { "points", 0 }, { "winCoinflipStreak", 0 }, { "loseCoinflipStreak", 0 }, { "roles", new BsonArray { } }, { "totalAttack", 0 }, { "totalDefense", 0 } }; DatabaseUtils.ChangeCollection("userData"); DatabaseUtils.MyMongoCollection.InsertOneAsync(document); }
public async Task Command() { List <User> top50 = (await DatabaseQueries.GetLimitAsync <User>(50, x => x.Experience > 0, x => x.Experience, true)).Where(x => !x.IsBlacklisted).ToList(); int i = 1; var embed = new KaguyaEmbedBuilder { Fields = new List <EmbedFieldBuilder>() }; foreach (User user in top50) { if (i > 10) { break; } SocketUser socketUser = Client.GetUser(user.UserId); embed.Fields.Add(new EmbedFieldBuilder { IsInline = false, Name = $"{i}. {socketUser?.ToString().Split('#').First() ?? $"[Unknown User: {user.UserId}]"}", Value = $"Level: {user.GlobalLevel():N0} ({user.PercentToNextLevel() * 100:N0}% {Centvrio.Emoji.Arrow.Right}" + $" Lvl {user.GlobalLevel() + 1:N0}) " + $"- Exp: {user.Experience:N0}" }); i++; } await SendEmbedAsync(embed); }
public async Task Command() { List <User> players = await DatabaseQueries.GetLimitAsync <User>(10, x => x.FishExp > 0, x => x.FishExp, true); DiscordShardedClient client = ConfigProperties.Client; var embed = new KaguyaEmbedBuilder(); embed.Title = "Kaguya Fishing Leaderboard"; int i = 0; foreach (User player in players) { i++; SocketUser socketUser = client.GetUser(player.UserId); List <Fish> fish = await DatabaseQueries.GetAllForUserAsync <Fish>(player.UserId, x => x.FishType != FishType.BAIT_STOLEN); embed.Fields.Add(new EmbedFieldBuilder { Name = $"{i}. {socketUser?.ToString().Split('#').First() ?? $"[Unknown User: {player.UserId}]"}", Value = $"Fish Level: `{player.FishLevel():0}` | Fish Exp: `{player.FishExp:N0}` | " + $"Fish Caught: `{fish.Count:N0}`" }); } await SendEmbedAsync(embed); }
public UserIdentity(SocketUser user) { UserName = user.ToString(); SystemName = user.Mention; IsAdmin = UserName == BBBInfo.TheCreator; Id = user.Id; }
public Task WhitelistAdd(SocketUser user = null) { if (user == null) { return(BetterReplyAsync("You must mention a user to add them to the whitelist.")); } if (SettingsManager.Configuration.DiscordWhitelist.Any(x => x.Key == Context.Guild.Id && x.Value.Contains(user.Id))) { return(BetterReplyAsync($"{BetterUserFormat(user)} is already whitelisted.", parameters: user.ToString())); } else { if (SettingsManager.Configuration.DiscordWhitelist.ContainsKey(Context.Guild.Id)) { SettingsManager.Configuration.DiscordWhitelist[Context.Guild.Id].Add(user.Id); } else { SettingsManager.Configuration.DiscordWhitelist.Add(Context.Guild.Id, new HashSet <ulong>() { user.Id }); } SettingsManager.Save(); LoggingManager.Log.Info($"{user.ToString()} ({user.Id}) was added to the whitelist by {Context.User.ToString()} ({Context.User.Id})"); return(BetterReplyAsync($"{BetterUserFormat(user)} was added to the whitelist.", parameters: user.ToString())); } }
public async Task UserEmoteEmbed([Remainder] SocketUser userparam) { try { Users user = new Users(); EmbedBuilder embed = new EmbedBuilder(); foreach (UserEmote usr in UserEmoteStorage._serverUsers) { if (usr.UserId == userparam.ToString()) { embed.AddField("User: "******"Emote: " + key.Key, "count: " + key.Value); } } break; } } await Context.Channel.SendMessageAsync("", false, embed.Build()); } catch (Exception e) { Console.WriteLine("error: " + e); } }
private async Task OnUserUnbanned(SocketUser socketUser, SocketGuild socketGuild) { var modlog = socketGuild.GetTextChannel(Global.Channels["banlog"]); var restAuditLogs = await socketGuild.GetAuditLogsAsync(10).FlattenAsync(); var unbanLog = restAuditLogs.FirstOrDefault(x => x.Action == ActionType.Unban); await modlog.EmbedAsync(new EmbedBuilder() .WithColor(9896005) .WithTitle("♻️ Unbanned User") .AddField(efb => efb .WithName("Username") .WithValue(socketUser.ToString()) .WithIsInline(true)) .AddField(efb => efb .WithName("ID") .WithValue(socketUser.Id.ToString()) .WithIsInline(true)) .AddField(efb => efb .WithName("By") .WithValue(unbanLog.User) .WithIsInline(true))); }
public async Task HelpAsync() { EmbedBuilder embed = new EmbedBuilder(); SocketUser user = Context.Message.Author; if (user.GetAvatarUrl() == null) { avatar = user.GetDefaultAvatarUrl(); } else { avatar = user.GetAvatarUrl(); } embed.WithAuthor(user.ToString(), avatar); embed.WithTitle(Context.Client.CurrentUser.Username.ToString() + " " + "Command options!"); embed.WithThumbnailUrl("https://i.imgur.com/dq4HKJr.png"); embed.WithDescription("**INFO: this bot is in `beta` and some of these features may not have full functionality yet*"); embed.AddField("`.j` / `.join`", "Joins voice channel that you are connected to!"); embed.AddField("`.p` / `.play`", "Starts playing in connected voice channel!"); embed.AddField("`.pp` / `.pause`", "Pause playback!"); embed.AddField("`.r` / `.resume`", "Resumes playback!"); embed.AddField("`.ss` / `.skip`", "Stops current song and moves to the next! (requires majority of all users in current voice channel)"); embed.AddField("`.v` / `.volume`", "Ajusts the players volume!"); embed.AddField("`.s` / `.stop`", "Stops playback! (removes all songs from queue)"); embed.AddField("`.l` / `.leave`", "Leave current voice channel!"); embed.AddField("`.q` / `.queue`", "View all songs in queue!"); embed.AddField("`.rp` / `.repeat`", "Infinate queue! (at the end of a song, it is re-added to queue at end)"); embed.AddField("`.list`", "Playlist manager main command!"); embed.AddField("`.list create <playlist name>`", "Create new playlist!"); embed.AddField("`.list del <playlist name>`", "Delete playlist and all its contents!"); embed.AddField("`.list add <playlist name> <track name>`", "Adds a track to the playlist"); embed.AddField("`.list rem <playlist name> <track name>`", "removes a track from playlist"); await ReplyAsync(null, false, embed.Build()); }
private async Task OnUserBanned(SocketUser socketUser, SocketGuild socketGuild) { var modlog = socketGuild.GetTextChannel(Global.Channels["modlog"]); var restAuditLogs = await socketGuild.GetAuditLogsAsync(10).FlattenAsync(); //As above, might be unnecessary as requests come in packs of 100. var banLog = restAuditLogs.FirstOrDefault(x => x.Action == ActionType.Ban); await modlog.EmbedAsync(new EmbedBuilder() .WithColor(9896005) .WithTitle("⛔️ Banned User") .AddField(efb => efb .WithName("Username") .WithValue(socketUser.ToString()) .WithIsInline(true)) .AddField(efb => efb .WithName("ID") .WithValue(socketUser.Id.ToString()) .WithIsInline(true)) .AddField(efb => efb .WithName("Reason") .WithValue(banLog.Reason) .WithIsInline(true)) .AddField(efb => efb .WithName("By") .WithValue(banLog.User) .WithIsInline(true))); }
public async Task checkMessageCountForRole(SocketUser user, ulong channelID) { string userName = user.ToString(); UserInfo userInfo = SupportingMethods.getUserInformation(userName); if (userInfo != null) { if (userInfo.IsBetaTester) { await addRole(user as SocketGuildUser, "Beta Tester", channelID); } if (userInfo.NumberOfMessages >= 10000) { await addRole(user as SocketGuildUser, "I wrote a novel", channelID); } else if (userInfo.NumberOfMessages >= 1000) { await addRole(user as SocketGuildUser, "I could write a novel", channelID); } else if (userInfo.NumberOfMessages >= 100) { await addRole(user as SocketGuildUser, "I'm liking this server", channelID); } else if (userInfo.NumberOfMessages >= 1) { await addRole(user as SocketGuildUser, "Hi and Welcome!", channelID); } } else { await createUserInDatabase(user, channelID); } }
/// <summary> /// Use to create new users only. /// </summary> /// <param name="user">Discord.Net socket user to create a RotnBotUser from.</param> public RotnBotUser(SocketUser user) { if (user != null) { DiscordUserId = user.Id; Username = user.ToString(); Points = 30; } }
private string GetUserName(SocketUser socketUser) { string userName = "******"; if (socketUser != null) { userName = socketUser.ToString(); } return(userName); }
//Posts whenever a user is banned. private async Task UserBanned(SocketUser user, SocketGuild server) { EmbedBuilder embed = new EmbedBuilder(); embed.WithTitle($"{user.ToString()} has been banned") .WithColor(Color.Magenta); embed.AddField("Banned", $"Name: `{user.ToString()}`\n ID: {user.Id}"); var channelId = Logging.getLogChannel(server.Id); //if no logging channel if (channelId == 0) { return; } var channel = _client.GetChannel(channelId) as IMessageChannel; await channel.SendMessageAsync("", false, embed.Build()); }
protected virtual Boolean isNewCharacter(SocketUser user, String name) { string tempDir = $"Resources/CharacterData/{user.ToString()}/{getSerialByName(name)}.json"; var dir = System.IO.Path.GetFullPath(tempDir); if (File.Exists(dir)) { return(false); } return(true); }
protected virtual void checkIfNewUser(SocketUser user) { string tempDir = $"Resources/CharacterData/{user.ToString()}"; var dir = System.IO.Path.GetFullPath(tempDir); // If directory does not exist, create it. if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } }
public async Task AvatarCmd([Summary("The user whose avatar should be fetched.")] SocketUser user = null) { if (user == null) { user = Context.User; } if (Context.Guild.Users.Where(x => x.ToString() == user.ToString()).Count() == 0) { return; } await ReplyAsync(embed : new EmbedBuilder().WithImageUrl(user.GetAvatarUrl(ImageFormat.Auto, 512)).WithColor(_misc.RandomColor()).Build()); }
public static void CreateUserInCompetition(SocketUser userName) { var user = userName as SocketGuildUser; var document = new BsonDocument { { "_id", (long)user.Id }, { "name", userName.ToString() }, { "credits", 10000 } }; DatabaseUtils.ChangeCollection("competition"); DatabaseUtils.MyMongoCollection.InsertOneAsync(document); }
public async Task TagsAsync([Remainder] SocketUser user) { var tags = await _db.GetTagsAsync(Context.Guild.Id, user.Id); if (tags.Count() == 0) { await ReplyAsync("This user has no tags yet!"); return; } var builder = GetEmbed(tags, user.ToString(), user.GetAvatarUrl()); await ReplyAsync("", embed : builder); }
/// <summary> /// Checks if the user is in the given list /// </summary> /// <param name="users"></param> /// <param name="user"></param> /// <returns></returns> private static bool IsUserInList(IEnumerable <string> users, SocketUser user) { // First scan ids if (users.Contains(user.Id.ToString(CultureInfo.InvariantCulture))) { return(true); } // Than the usernames (with #xxxx) if (users.Contains(user.ToString())) { return(true); } return(false); }
public static void createUserInDatabase(SocketUser userName) { var user = userName as SocketGuildUser; var date = user.JoinedAt.ToString(); var document = new BsonDocument { { "name", userName.ToString() }, { "dateJoined", date }, { "numberOfMessages", 0 }, { "isBetaTester", false }, { "reactionCount", 0 }, { "experience", 0 }, { "points", 0 } }; Collection.InsertOneAsync(document); }
private async void NotifyAfk(SocketUserMessage message, string id, SocketUser user) { var rawData = await _manager.GetUsersByField("UserId", id); var data = rawData.FirstOrDefault(); EmbedBuilder builder = new EmbedBuilder(); builder.WithAuthor($"{user.ToString()} is now AFK", user.GetAvatarUrl(ImageFormat.Png, 2048)); builder.WithColor(GetRandomColour()); builder.WithDescription($"AFK Since : `{data.AfkTime}`"); builder.AddField("Reason", data.AfkReason); if (data.AfkAttachment != "") { builder.WithImageUrl(data.AfkAttachment); } await message.Channel.SendMessageAsync(embed : builder.Build()); }
private static UserAccount CreateUserAccount(SocketUser user, ulong guildId) { string userName = user.ToString(); UserAccount newAccount = new UserAccount() { ID = user.Id, Name = userName, Points = 0, XP = 0, IsMuted = false, NumberOfWarnings = 0, GuildId = guildId }; accounts.Add(newAccount); SaveAccounts(); return(newAccount); }
/// <summary> /// Adds a mute record. /// </summary> /// <param name="user">The user to mute.</param> /// <param name="muter">The user which invoked the mute operation.</param> /// <param name="timestamp">When the mute was issued.</param> /// <param name="duration">The duration, in minutes, of the mute.</param> /// <param name="reason">The reason for the mute.</param> /// <returns><c>true</c> if the mute was successfully added; <c>false</c> if the user is already muted.</returns> public static async Task <bool> AddMuteAsync( SocketUser user, SocketUser muter, DateTimeOffset timestamp, long?duration = null, string reason = null) { var mute = new Mute { UserId = user.Id, Username = user.ToString(), Reason = reason, Duration = duration, MuterName = muter.ToString(), Timestamp = timestamp }; return(await AddMuteAsync(mute)); }
private string GetUserName(SocketUser socketUser) { string userName = "******"; try { if (socketUser != null) { userName = socketUser.ToString(); SocketGuildUser user = socketUser as SocketGuildUser; if (user?.Nickname != null) { userName += " NickName: " + user.Nickname; } } } catch { } return(userName); }
public Task WhitelistRemove(SocketUser user = null) { if (user == null) { return(BetterReplyAsync("You must mention a user to remove them from the whitelist.")); } if (SettingsManager.Configuration.DiscordWhitelist.Any(x => x.Key == Context.Guild.Id && x.Value.Contains(user.Id))) { SettingsManager.Configuration.DiscordWhitelist[Context.Guild.Id].Remove(user.Id); SettingsManager.Save(); LoggingManager.Log.Info($"{user.ToString()} ({user.Id}) was removed from the whitelist by {Context.User.ToString()} ({Context.User.Id})"); return(BetterReplyAsync($"{BetterUserFormat(user)} was removed from the whitelist.", parameters: user.ToString())); } else { return(BetterReplyAsync($"{BetterUserFormat(user)} is not on the whitelist.", parameters: user.ToString())); } }
public async Task Command() { List <ServerExp> top50 = await DatabaseQueries.GetLimitAsync <ServerExp>(50, x => x.Exp > 0 && x.ServerId == Context.Guild.Id, x => x.Exp, true); int i = 1; Server server = await DatabaseQueries.GetOrCreateServerAsync(Context.Guild.Id); var embed = new KaguyaEmbedBuilder { Title = $"Exp Leaderboard for {Context.Guild}", Fields = new List <EmbedFieldBuilder>() }; foreach (ServerExp element in top50) { if (i > 10) { break; } SocketUser socketUser = Client.GetUser(element.UserId); User user = await DatabaseQueries.GetOrCreateUserAsync(element.UserId); embed.Fields.Add(new EmbedFieldBuilder { IsInline = false, Name = $"{i}. {socketUser?.ToString().Split('#').First() ?? $"[Unknown User: {user.UserId}]"}", Value = $"Level: {user.ServerLevel(server):N0} ({user.PercentToNextServerLevel(server) * 100:N0}% {Centvrio.Emoji.Arrow.Right}" + $" Lvl {user.ServerLevel(server) + 1:N0}) " + $"- Exp: {element.Exp:N0}" }); i++; } await SendEmbedAsync(embed); }
public async Task UserInfo() { SocketUser user = Context.User; if (Context.Channel.Id == (ulong)609542348287770624) { string joined = await Database.DbHandler.GetUserJoinedDate(user.Id.ToString()); int mensajes = await Database.DbHandler.GetUserMessages(user.Id.ToString()); string joined_msg; if (joined == "0") { joined_msg = "Sin registrar"; } else { joined_msg = joined; } EmbedBuilder builder = new EmbedBuilder(); builder.WithTitle($"Estadísticas de {user.ToString()}"); builder.AddField("Fecha de creación", $"{user.CreatedAt}", true); builder.AddField("ID del usuario", $"{user.Id}", true); builder.AddField("Fecha de entrada al servidor", $"{joined_msg}", true); builder.AddField("Mensajes totales en ODCode", $"{mensajes}", true); builder.WithThumbnailUrl(user.GetAvatarUrl()); builder.WithColor(Color.Red); await Context.Channel.SendMessageAsync("", false, builder.Build()); } else { await ReplyAsync("⚠️ Dirígete a #comandos-bot para usar mis comandos."); } }