Exemple #1
0
        public async Task UserAvatar([Remainder] string a_name)
        {
            if (Context.User.Id != Global.Config.Admin)
            {
                return;
            }

            string basePath = Path.GetFullPath("avatar/");
            string uri      = Path.GetFullPath(Path.Combine(basePath, a_name));

            if (!uri.StartsWith(basePath))
            {
                await Context.Channel.SendMessageAsync($"{Context.User.Mention} Yeah nah.");

                return;
            }

            try
            {
                using (var fileStream = File.OpenRead(uri))
                {
                    var img = new Discord.Image(fileStream);
                    await Context.Client.CurrentUser.ModifyAsync(p => p.Avatar = img);
                }
            }
            catch (IOException ex)
            {
                await Context.Channel.SendMessageAsync($"{Context.User.Mention} Couldn't read {a_name}: {ex.Message}");

                return;
            }

            await Context.Channel.SendMessageAsync($"{Context.User.Mention} Avatar updated. :tada:");
        }
Exemple #2
0
        public async Task SetAvatar(string path)
        {
            var user = Client.CurrentUser;

            if (File.Exists(path))
            {
                using (var fs = File.OpenRead(path))
                {
                    var img = new Discord.Image(fs);
                    await Task.Delay(21); // This should keep Discord from rate limiting the bot

                    await user.ModifyAsync(x =>
                    {
                        x.Avatar = img;
                    });
                }
                CurrentAvatar = Path.GetFileName(path);
            }
        }
Exemple #3
0
        //changes bots name and avatar
        private async void Switchavatar()
        {
            int num = random.Next(avatars.Count);

            Discord.Image img = new Discord.Image(avatars[num][1]);
            try
            {
                await client.CurrentUser.ModifyAsync(x =>
                {
                    try { x.Avatar = img; }
                    catch { }
                    try { x.Username = avatars[num][0]; }
                    catch { x.Username = "******"; }
                });

                Console.WriteLine("Complete change avatar request");
            }
            catch { Console.WriteLine("Unable to complete change avatar request"); }
            Program.CurrentName = client.CurrentUser.Username;
            Program.CurrentUrl  = client.CurrentUser.GetAvatarUrl();
        }