public async Task Avatar(SocketUser user = null) { if (user == null) { await BetterReplyAsync("You must mention a user to see their avatar.", parameters : "user null"); return; } await Context.Channel.TriggerTypingAsync(); using HttpResponseMessage response = await Http.Client.GetAsync(user.GetAvatarUrl(size: 1024)); if (response.IsSuccessStatusCode) { using HttpContent content = response.Content; Stream stream = await content.ReadAsStreamAsync(); if (stream.Length > Constants.DiscordMaximumFileSize) { await BetterReplyAsync("There was an error processing the avatar. Re-upload was too large."); } else { string changes = StatisticsManager.GetUserAvatarChanges(user.Id); List <string> chunks = changes.SplitIntoChunksPreserveNewLines(1930); string message = null; if (chunks.Count == 0) { message = $"● Avatar of {BetterUserFormat(user)}"; } else if (chunks.Count == 1) { foreach (string chunk in chunks) { message = $"● Previous avatars of {BetterUserFormat(user)} ```{chunk}```{Environment.NewLine}Current avatar:"; } } else { Backblaze.File uploadedFile = await Backblaze.UploadTemporaryFileAsync(changes, $"{user.Id}/{Backblaze.ISOFileNameDate("txt")}"); if (uploadedFile is Backblaze.File) { message = $"● There are too many previous avatars to list here for {BetterUserFormat(user)} <{uploadedFile.ShortUrl}>{Environment.NewLine}{Environment.NewLine}Current avatar:"; } } stream.Seek(0, SeekOrigin.Begin); await BetterSendFileAsync(stream, $"{user.Id}_avatar.{(user.AvatarId.StartsWith("a_") ? "gif" : "png")}", message, parameters : $"{user} ({user.Id})"); } } else { await BetterReplyAsync("There was an error processing the avatar. Avatar download failed.", parameters : $"{user} ({user.Id})"); } }
public static void Main(string[] args) { CloudRail.AppKey = "[Your CloudRail Key]"; String serviceName = SelectService(); AmazonS3 amazons3 = new AmazonS3( null, "[Your S3 Access Key ID]", "[Your S3 Secret Access Key]", "[Your AWS region]" ); Backblaze backblaze = new Backblaze( null, "[Your Backblaze Account ID]", "[Your Backblaze App Key]" ); GoogleCloudPlatform googlecloudplatform = new GoogleCloudPlatform( null, "[Your Google Client Email]", "[Your Google Private Key]", "[Your Google Project ID]" ); MicrosoftAzure microsoftazure = new MicrosoftAzure( null, "[Your Azure Account Name]", "[Your Azure Access Key]" ); Rackspace rackspace = new Rackspace( null, "[Your Rackspace User Name]", "[Your Rackspace API Key]", "[Your Rackspace Region]" ); switch (serviceName) { case "1": service = amazons3; break; case "2": service = backblaze; break; case "3": service = googlecloudplatform; break; case "4": service = microsoftazure; break; case "5": service = rackspace; break; } ShowBuckets(); GetNextUserCommand(); }
public async Task NameChangesById(string input = null) { if (!ulong.TryParse(input, out ulong id)) { await BetterReplyAsync("You must supply a valid user id.", parameters : "user null"); return; } await Context.Channel.TriggerTypingAsync(); string changes = StatisticsManager.GetUserChanges(Context.Guild.Id, id); if (string.IsNullOrWhiteSpace(changes)) { await BetterReplyAsync($"There is no name change data for {id}. Maybe they just never changed their name. :shrug:", parameters : $"({id})"); return; } List <string> chunks = changes.SplitIntoChunksPreserveNewLines(1930); if (chunks.Count == 1) { foreach (string chunk in chunks) { await BetterReplyAsync($"● Name changes for {id} ```{chunk}```", parameters : $"({id})"); } } else { Backblaze.File uploadedFile = await Backblaze.UploadTemporaryFileAsync(changes, $"{id}/{Backblaze.ISOFileNameDate("txt")}"); string message; if (uploadedFile is Backblaze.File) { message = uploadedFile.ShortUrl; } else { message = "There was an error uploading the temporary file."; } await BetterReplyAsync($"There are too many name changes to display here. {message}", parameters : $"({id})"); } }
private static async Task ProcessUserUpdated(IUser oldUser, IUser newUser) { // Bot check //try { // if (WubbysFunHouse.IsServerBot(newUser.Id)) { // if (oldUser.Status == UserStatus.Online & newUser.Status == UserStatus.Offline) { // await SendMessageAsync(WubbysFunHouse.ModLogsChannelId, $":warning: The bot {newUser.Mention} is **offline**!"); // } else if (oldUser.Status == UserStatus.Offline & newUser.Status == UserStatus.Online) { // await SendMessageAsync(WubbysFunHouse.ModLogsChannelId, $":white_check_mark: The bot {newUser.Mention} is back **online**."); // } // } //} catch (Exception ex) { // LoggingManager.Log.Error(ex); //} // User changes try { StatisticsManager.NameChangeType changeType = StatisticsManager.NameChangeType.None; ulong? guildId = null; string oldUsername = null, newUsername = null; string oldDiscriminator = null, newDiscriminator = null; string oldNickname = null, newNickname = null; string backblazeAvatarBucket = null, backblazeAvatarFilename = null, backblazeAvatarUrl = null; if (oldUser is SocketGuildUser & newUser is SocketGuildUser) { SocketGuildUser oldSocketUser = oldUser as SocketGuildUser; SocketGuildUser newSocketUser = newUser as SocketGuildUser; guildId = newSocketUser.Guild.Id; if (oldSocketUser.Nickname != newSocketUser.Nickname) { changeType |= StatisticsManager.NameChangeType.Display; oldNickname = oldSocketUser.Nickname; newNickname = newSocketUser.Nickname; } } if (oldUser.Username != newUser.Username) { changeType |= StatisticsManager.NameChangeType.Username; oldUsername = oldUser.Username; newUsername = newUser.Username; } if (oldUser.Discriminator != newUser.Discriminator) { changeType |= StatisticsManager.NameChangeType.Discriminator; oldDiscriminator = oldUser.Discriminator; newDiscriminator = newUser.Discriminator; } if (oldUser.AvatarId != newUser.AvatarId) { try { ImageFormat imageFormat = newUser.AvatarId.StartsWith("a_") ? ImageFormat.Gif : ImageFormat.Png; Task <MemoryStream> download = Http.GetStreamAsync(newUser.GetAvatarUrl(imageFormat, 1024)); using MemoryStream data = await download; if (download.IsCompletedSuccessfully) { Backblaze.File avatarUpload = await Backblaze.UploadAvatarAsync(data, $"{newUser.Id}/{Backblaze.ISOFileNameDate(imageFormat.ToString().ToLower())}"); backblazeAvatarBucket = avatarUpload.BucketName; backblazeAvatarFilename = avatarUpload.FileName; backblazeAvatarUrl = avatarUpload.ShortUrl; changeType |= StatisticsManager.NameChangeType.Avatar; } else { LoggingManager.Log.Error(download.Exception); backblazeAvatarBucket = null; backblazeAvatarFilename = null; backblazeAvatarUrl = null; } } catch { } } if (changeType != StatisticsManager.NameChangeType.None) { StatisticsManager.InsertUserChange(DateTime.UtcNow, guildId, newUser.Id, changeType, oldUsername, newUsername, oldDiscriminator, newDiscriminator, oldNickname, newNickname, backblazeAvatarBucket, backblazeAvatarFilename, backblazeAvatarUrl); } } catch (Exception ex) { LoggingManager.Log.Error(ex); } }
private static async Task UserJoined(SocketGuildUser user) { // Log join if (_DiscordClient.GetChannel(WubbysFunHouse.UserLogsChannelId) is IMessageChannel logChannel) { await logChannel.SendMessageAsync($"`[{DateTime.UtcNow.ToString(Constants.DateTimeFormatMedium)}]` :inbox_tray: {user} (`{user.Id}`) has joined."); } // Username check if (!user.Username.All(x => x <= sbyte.MaxValue)) { _ = Task.Run(async() => { await Task.Delay(1000); try { await WubbysFunHouse.AddRoleAsync(user, WubbysFunHouse.MutedRoleId, "Auto-muted on join due to weird username."); await SendMessageAsync(WubbysFunHouse.ModLogsChannelId, $":exclamation: {user.Mention} was auto-muted on join due to due to weird username."); await Task.Run(async() => { await Task.Delay(8000); if (!user.Roles.Any(x => x.Id == WubbysFunHouse.MutedRoleId)) { await WubbysFunHouse.AddRoleAsync(user, WubbysFunHouse.MutedRoleId, "Auto-muted on join due to weird username (second attempt)."); await SendMessageAsync(WubbysFunHouse.ModLogsChannelId, $":bangbang: {user.Mention} was auto-muted on join due to due to weird username (second attempt, first one either failed or was overridden <@{Constants.XathzUserId}>)."); } }); } catch (Exception ex) { LoggingManager.Log.Error(ex); } }); } // Auto-mute accounts that have been created recently if (user.CreatedAt.AddDays(7) > DateTimeOffset.Now) { _ = Task.Run(async() => { await Task.Delay(2000); try { await WubbysFunHouse.AddRoleAsync(user, WubbysFunHouse.MutedRoleId, "Auto-muted on join due to account being younger than a week."); await SendMessageAsync(WubbysFunHouse.ModLogsChannelId, $":anger: {user.Mention} was auto-muted on join due to account being younger than a week."); } catch (Exception ex) { LoggingManager.Log.Error(ex); } }); } if (user == null) { LoggingManager.Log.Error("User joined, user is null"); return; } if (string.IsNullOrEmpty(user.Guild.Id.ToString())) { LoggingManager.Log.Error("User joined, guild id is null"); return; } await _DiscordClient.GetGuild(user.Guild.Id).DownloadUsersAsync(); user = _DiscordClient.GetGuild(user.Guild.Id).GetUser(user.Id); if (string.IsNullOrEmpty(user.AvatarId)) { LoggingManager.Log.Error("User joined, avatar id is null!"); return; } // ======== Task runner = Task.Run(async() => { try { StatisticsManager.NameChangeType changeType = StatisticsManager.NameChangeType.Username | StatisticsManager.NameChangeType.Discriminator | StatisticsManager.NameChangeType.Display; string backblazeAvatarBucket = null, backblazeAvatarFilename = null, backblazeAvatarUrl = null; try { ImageFormat imageFormat = user.AvatarId.StartsWith("a_") ? ImageFormat.Gif : ImageFormat.Png; Task <MemoryStream> download = Http.GetStreamAsync(user.GetAvatarUrl(imageFormat, 1024)); using MemoryStream data = await download; if (download.IsCompletedSuccessfully) { Backblaze.File avatarUpload = await Backblaze.UploadAvatarAsync(data, $"{user.Id}/{Backblaze.ISOFileNameDate(imageFormat.ToString().ToLower())}"); backblazeAvatarBucket = avatarUpload.BucketName; backblazeAvatarFilename = avatarUpload.FileName; backblazeAvatarUrl = avatarUpload.ShortUrl; changeType |= StatisticsManager.NameChangeType.Avatar; } else { LoggingManager.Log.Error(download.Exception); backblazeAvatarBucket = null; backblazeAvatarFilename = null; backblazeAvatarUrl = null; } } catch { } StatisticsManager.InsertUserChange(DateTime.UtcNow, user.Guild.Id, user.Id, changeType, null, user.Username, null, user.Discriminator, null, user.Nickname, backblazeAvatarBucket, backblazeAvatarFilename, backblazeAvatarUrl); } catch (Exception ex) { LoggingManager.Log.Error(ex); } }); }