Пример #1
0
    async Task <string> IBirthdayProvider.SetBirthdayAsync(DiscordUserId userId,
                                                           short month,
                                                           short day)
    {
        if (month is < 1 or > 12)
        {
            return(":warning: Value of `month` must be between 1 and 12.");
        }

        if (!DateOnly.TryParseExact($"2000.{month:D2}.{day:D2}", "yyyy.MM.dd", out var parsedDate))
        {
            return(":warning: Value of `day` is not valid for the given `month`.");
        }

        if (!_userStore.TryGetUser(userId, out var user))
        {
            return(":warning: Failed to set birthday. User couldn't be identified.");
        }

        var birthdaySet = await _databaseAccess.SetBirthdayAsync(user !, parsedDate);

        return(birthdaySet
                   ? ":white_check_mark: Birthday set successfully."
                   : ":warning: Failed to set birthday.");
    }
Пример #2
0
        public override int GetHashCode()
        {
            var hashCode = -584914611;

            hashCode = hashCode * -1521134295 + EqualityComparer <Account[]> .Default.GetHashCode(Accounts);

            hashCode = hashCode * -1521134295 + DiscordUserId.GetHashCode();
            return(hashCode);
        }
Пример #3
0
    async Task <string> IBirthdayProvider.DeleteBirthdayAsync(DiscordUserId userId)
    {
        if (!_userStore.TryGetUser(userId, out var user))
        {
            return(":warning: Failed to delete birthday. User couldn't be identified.");
        }
        var birthdayDeleted = await _databaseAccess.DeleteUserBirthdayAsync(user !);

        return(birthdayDeleted
                   ? ":white_check_mark: Birthday deleted successfully."
                   : ":warning: Failed to delete birthday.");
    }
            public override int GetHashCode()
            {
                unchecked {
                    var hashCode = Key != null?Key.GetHashCode() : 0;

                    hashCode = (hashCode * 397) ^ (int)KeyScope;
                    hashCode = (hashCode * 397) ^ ForumUserId.GetHashCode();
                    hashCode = (hashCode * 397) ^ DiscordUserId.GetHashCode();
                    hashCode = (hashCode * 397) ^ GuildId.GetHashCode();
                    hashCode = (hashCode * 397) ^ CreatedAt.GetHashCode();
                    return(hashCode);
                }
            }
Пример #5
0
    EmbedData IIgnoreGuard.EnsureOnIgnoreList(DiscordUserId userID,
                                              string username,
                                              int minutes)
    {
        // Update or insert value
        var ignoreUntil = DateTime.Now.ToUniversalTime().AddMinutes(minutes);

        _ignoreList[userID] = ignoreUntil;
        return(new EmbedData
        {
            Title = "Added to ignore list",
            Color = Colors.Green,
            Description = $"**{username}**: You will be ignored for the next {minutes} minutes "
                          + $"(until {ignoreUntil:dd.MM.yyyy HH:mm:ss} UTC) in the "
                          + $"environment **{_botInformationProvider.GetEnvironmentName()}**."
        });
Пример #6
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////
    #region Private Methods

    private async Task <(User User, bool IsNew)> GetUserInternal(DiscordUserId userID)
    {
        try
        {
            await _semaphore.WaitAsync();

            if (!_isInitialized)
            {
                throw new InvalidOperationException("Store is not initialized.");
            }

            var storedUser = _store.SingleOrDefault(m => m.DiscordUserId == userID);
            if (storedUser != null)
            {
                return(storedUser, false);
            }
        }
        finally
        {
            _semaphore.Release();
        }

        try
        {
            await _semaphore.WaitAsync();

            // If the user wasn't found, make sure it exists in the database and load it
            var databaseUser = await _databaseAccess.GetOrAddUserAsync(userID);

            _store.Add(databaseUser.User);
            return(databaseUser);
        }
        finally
        {
            _semaphore.Release();
        }
    }
Пример #7
0
 public bool Equals(DiscordUserId other)
 {
     return(Id == other.Id);
 }
Пример #8
0
 public override int GetHashCode()
 {
     return(DiscordUserId.GetHashCode());
 }
Пример #9
0
 /// <summary>
 /// Converts the <paramref name="userId"/> into the mention syntax.
 /// </summary>
 /// <param name="userId">The <see cref="DiscordUserId"/> to convert into the mention syntax.</param>
 /// <returns>A string that will cause a mention in Discord.</returns>
 public static string ToMention(this DiscordUserId userId) => $"<@{userId}>";