public async Task danbooru(string character) { try { string arg = character; if (arg != null) { DanbooruDownloader don = new DanbooruDownloader(); string file = await don.DownloadRandomimage(arg); if (file == null) { await ReplyAsync(String.Format("Did not find a random image to send you {0} from danbooru (based boards ) for {1}.", Context.User.Mention, character)); return; } Stream fil = File.OpenRead(file); await Context.Channel.SendFileAsync(fil, file, String.Format("{0} got a random image for : {1} from danbooru (based boards ) " , Context.User.Mention, arg)); File.Delete(file); } } catch (Exception ex) { CommonTools.ErrorReporting(ex); } }
public async Task danbooruRnd(string character) { try { string arg = character; if (arg != null) { Stream fil = null; int i = 0; Random rnd = new Random(); DanbooruDownloader don = new DanbooruDownloader(); string file = await don.DownloadRandomimage(arg); if (file != null) { fil = File.OpenRead(file); } IAsyncEnumerable <IReadOnlyCollection <IUser> > tusers = Context.Channel.GetUsersAsync(CacheMode.AllowDownload); var susers = tusers.ToList(); List <IUser> ausers = tusers.Flatten().Result.ToList(); List <IUser> users = ausers.FindAll(x => x.IsBot == false); i = rnd.Next(users.Count); IUser user = users[i]; if (fil != null) { var channel = await user.GetOrCreateDMChannelAsync(); if (channel != null) { await ReplyAsync(String.Format("Sending a random image for : {0} from danbooru (based boards ) to {1}", arg, user.Mention)); await channel.SendFileAsync(fil, file, String.Format("{0} Get a random image for : {0} from danbooru (based boards ) " , user.Mention, arg)); } ///CreatePrivateChannelAsync(user.Id).Result.SendFile(file); // await e.Channel.SendFile(file); } File.Delete(file); } } catch (Exception ex) { CommonTools.ErrorReporting(ex); } }
public override async Task GuildMemberUpdated(SocketGuildUser arg1, SocketGuildUser arg2) { try { await base.GuildMemberUpdated(arg1, arg2); if (arg1.Status != arg2.Status && arg1.IsBot == false && arg2.IsBot == false) { if (arg1.Status != Discord.UserStatus.Online && arg2.Status == Discord.UserStatus.Online) // && arg2.Status!= Discord.UserStatus.DoNotDisturb && arg2.) { UserManager usermngr = new UserManager(); var user = await usermngr.GetUserbyId(Convert.ToString(arg1.Id)); if (user != null) { DateTime date = DateTime.Now; GiftHistoryManager giftmngr = new GiftHistoryManager(); var birth = user.Birthday; if (date.Day == birth.Day && date.Month == birth.Month) { FavoriteCharactersManager fvmngr = new FavoriteCharactersManager(); var fchar = fvmngr.GetUserFavorite(Convert.ToString(user.Id)); if (fchar != null && await giftmngr.isGiftGiven(user.Id, Convert.ToString(arg1.Guild.Id), DateTime.Now.Year) == false) { int i = 0; Random rnd = new Random(); i = rnd.Next(fchar.Count - 1); if (i > 0) { DanbooruDownloader san = new DanbooruDownloader(); string file = await san.DownloadRandomimage(fchar[i].CharacterName); var dmchannel = await arg1.GetOrCreateDMChannelAsync(); if (dmchannel != null) { if (file == null) { //await dmchannel.SendMessageAsync(String.Format("Did not find a random image to send you {0} from danbooru complex for {1}.", // arg2.Mention, fchar[i].CharacterName)); return; } Stream fil = File.OpenRead(file); await dmchannel.SendFileAsync(fil, file, String.Format("{0} Happy Birthday ! Sending you a random image for : {1} from danbooru (based boards ) as a present!" , arg2.Mention, fchar[i].CharacterName)); } File.Delete(file); await giftmngr.AddGift(user.Id, fchar[i].CharacterName, Convert.ToString(arg1.Guild.Id)); } } } } } } //return Task.CompletedTask; } catch (Exception ex) { CommonTools.ErrorReporting(ex); //return Task.CompletedTask; } }