Ejemplo n.º 1
0
        public async Task GuildBlessChannelAsync(ITextChannel channel)
        {
            var guild = await _db.Guilds.FindAsync(Context.Guild.Id);

            guild.LolaBlessGame = channel.Id;

            await _db.SaveChangesAsync();

            await Context.Message.AddReactionAsync(ConfirmEmoji);
        }
Ejemplo n.º 2
0
        public async Task SetBirthdayAsync(
            [Remainder]
            [Summary("Your birthday with the year optional. " +
                     "The format 'January 1, 1900' will work best. ")]
            DateTime?birthday = null)
        {
            var user = await _db.Users.FindAsync(Context.User.Id) ?? new User((IGuildUser)Context.User);

            if (user.Timezone is null)
            {
                await ReplyAsync("Your timezone is not set, you can set one by doing `l!timezone +8:00`.");
            }

            user.BirthDate = birthday;
            user.HasYear   = birthday is not null && birthday?.Year != DateTime.Now.Year;
            _db.Users.Update(user);
            await _db.SaveChangesAsync();

            if (birthday is null)
            {
                await ReplyAsync("Your birthday was removed");
            }
            else
            {
                var timezone = user.Timezone ?? TimeSpan.FromHours(8);
                var offset   = new DateTimeOffset((DateTime)birthday !, timezone);

                await ReplyAsync($"Set your birthday to {offset.ToString((bool) user.HasYear ? "dddd, MMMM d, yyyy K" : "MMMM d K")}.");
            }
        }
Ejemplo n.º 3
0
        public async Task SetStreamTimeAsync(string title, DateTimeOffset time, Platform platform)
        {
            var stream = new Stream
            {
                Title    = title,
                Time     = time,
                Platform = platform
            };

            _db.Streams.Add(stream);
            await _db.SaveChangesAsync();

            await Context.Message.AddReactionAsync(new Emoji("✅"));
        }
Ejemplo n.º 4
0
        public async Task AddAccountAsync()
        {
            var user = await _db.Users.FindAsync(Context.User.Id);

            if (user is null)
            {
                _logger.LogWarning("User {0} was not found in the database", Context.User);
                return;
            }

            var loginType = new EmbedFieldBuilder()
                            .WithName("Login Types (Type it in)")
                            .WithValue("※ Email" + Environment.NewLine +
                                       "※ Username" + Environment.NewLine +
                                       "※ Twitter" + Environment.NewLine +
                                       "※ Facebook" + Environment.NewLine +
                                       "※ PlayStation");

            var answers = await this.CreatePromptCollection <AccountPrompts>()
                          .WithTimeout(30)
                          .WithPrompt(AccountPrompts.LoginType, "Enter your account login type.", new[] { loginType })
                          .ThatHas((string s, bool b, out LoginType a) => Enum.TryParse(s, b, out a))
                          .WithPrompt(Username, "Enter your username/email")
                          .Collection.GetAnswersAsync();

            var account = new GenshinAccount
            {
                AccountType = answers.Get <LoginType>(AccountPrompts.LoginType),
                Username    = answers.Get <string>(Username)
            };

            user.GenshinAccounts.Add(account);
            user.ActiveGenshinAccount = account;
            await _db.SaveChangesAsync();

            await ReplyAsync("Your account was added.");
        }
Ejemplo n.º 5
0
        public async Task Handle(MessageReceivedNotification notification, CancellationToken cancellationToken)
        {
            var rawMessage = notification.Message;

            if (!(rawMessage is SocketUserMessage message))
            {
                return;
            }

            if (message.Source != MessageSource.User)
            {
                return;
            }

            var author = notification.Message.Author;
            var user   = await _db.Users.FindAsync(author.Id);

            if (user is null)
            {
                user = new User((IGuildUser)author);
                await _db.Users.AddAsync(user, cancellationToken);
            }

            _log.LogTrace($"[{{0}}] {{1}}: {notification.Message.Content}",
                          notification.Message.Channel,
                          notification.Message.Author);
            user.LastSeenAt = DateTimeOffset.Now;
            await _db.SaveChangesAsync(cancellationToken);

            var argPos  = 0;
            var context = new SocketCommandContext(_discord, message);

            if (!(message.HasStringPrefix("l!", ref argPos, StringComparison.OrdinalIgnoreCase) ||
                  message.HasMentionPrefix(_discord.CurrentUser, ref argPos)))
            {
                return;
            }

            var result = await _commands.ExecuteAsync(context, argPos, _services);

            if (result is null)
            {
                _log.LogWarning("Command with context {0} ran by user {1} is null.", context, message.Author);
            }
            else if (!result.IsSuccess)
            {
                await CommandFailedAsync(context, result);
            }
        }
Ejemplo n.º 6
0
        public async Task Handle(JoinedGuildNotification notification, CancellationToken cancellationToken)
        {
            var guild = await _db.Guilds.FindAsync(notification.Guild.Id);

            if (guild is null)
            {
                guild = new Guild
                {
                    Id    = notification.Guild.Id,
                    Owner = notification.Guild.OwnerId
                };
                _db.Guilds.Add(guild);
            }

            await _db.SaveChangesAsync(cancellationToken);
        }
Ejemplo n.º 7
0
        public async Task Handle(ReadyNotification notification, CancellationToken cancellationToken)
        {
            var missingGuilds = _client.Guilds
                                .Where(socketGuilds =>
                                       !_db.Guilds.ToList().Select(g => g.Id).Contains(socketGuilds.Id));

            foreach (var guild in missingGuilds)
            {
                var newGuild = new Guild
                {
                    Id    = guild.Id,
                    Owner = guild.Id
                };
                _db.Guilds.Add(newGuild);
            }

            await _db.SaveChangesAsync(cancellationToken);
        }
Ejemplo n.º 8
0
        private async Task AwardUserAsync(Blessing blessing, SocketGuild guild, SocketGuildUser guildUser)
        {
            if (blessing.Type == BlessingType.Kiss)
            {
                var role = guild.GetRole(731807968940523560);
                await guildUser.AddRoleAsync(role);
            }

            var user = await _db.Users
                       .Include(u => u.Stats)
                       .Include(u => u.Stats.BlessingResults)
                       .FirstOrDefaultAsync(u => u.Id == guildUser.Id);

            if (user is null)
            {
                return;
            }

            user.Stats.Rolls++;
            user.Stats[blessing.Type].Amount++;

            await _db.SaveChangesAsync();
        }
Ejemplo n.º 9
0
        public async Task SetTimezoneAsync([Remainder][Summary("Your timezone in +8:00 format")]
                                           string offset)
        {
            var timezone = _timezoneRegex.Match(offset);
            var m        = timezone.Groups["m"].Success ? timezone.Groups["m"].Value : "0";

            if (!(timezone.Success &&
                  int.TryParse($"{timezone.Groups["sign"].Value}{timezone.Groups["h"].Value}", out var hours) &&
                  int.TryParse(m, out var minutes)))
            {
                await ReplyAsync("The timezone you provided was invalid");

                return;
            }

            var timespan = new TimeSpan(hours, minutes, 0);
            var user     = await _db.Users.FindAsync(Context.User.Id);

            user.Timezone = timespan;

            await _db.SaveChangesAsync();

            await ReplyAsync($"Your timezone has been updated to {timespan.Humanize()}");
        }
Ejemplo n.º 10
0
        public async Task ResetQueueAsync()
        {
            var karaoke = await GetKaraokeAsync(Context.Guild.Id);

            _db.RemoveRange(karaoke.Queue);
            await _db.SaveChangesAsync();

            karaoke.Queue.Clear();

            await PauseKaraokeAsync();
            await ReplyAsync("Queue has been reset!");
        }