public async Task HandleNotificationAsync(PromotionActionCreatedNotification notification, CancellationToken cancellationToken)
        {
            // TODO: Temporary workaround, remove as part of auth rework.
            if (AuthorizationService.CurrentUserId is null)
            {
                await AuthorizationService.OnAuthenticatedAsync(DiscordSocketClient.CurrentUser);
            }

            if (await DesignatedChannelService.AnyDesignatedChannelAsync(notification.Data.GuildId, DesignatedChannelType.PromotionLog))
            {
                var message = await FormatPromotionLogEntryAsync(notification.Id);

                if (message == null)
                {
                    return;
                }

                await DesignatedChannelService.SendToDesignatedChannelsAsync(
                    await DiscordSocketClient.GetGuildAsync(notification.Data.GuildId), DesignatedChannelType.PromotionLog, message);
            }

            if (await DesignatedChannelService.AnyDesignatedChannelAsync(notification.Data.GuildId, DesignatedChannelType.PromotionNotifications))
            {
                var embed = await FormatPromotionNotificationAsync(notification.Id, notification.Data);

                if (embed == null)
                {
                    return;
                }

                await DesignatedChannelService.SendToDesignatedChannelsAsync(
                    await DiscordSocketClient.GetGuildAsync(notification.Data.GuildId), DesignatedChannelType.PromotionNotifications, "", embed);
            }
        }
Beispiel #2
0
        public override IList <Response> Execute(SenderSettings senderDetail, IMessageDetail args)
        {
            ServerSettings       serverSettings = senderDetail.ServerSettings;
            CommandMessageHelper command        = new CommandMessageHelper(serverSettings.CommandSymbol, args.Message);

            if (Constants.IsBotOwner(args.UserId))
            {
                Task.Run(async() =>
                {
                    string name = command.CommandDetail;
                    if (args.ChannelId != Constants.ConsoleId)
                    {
                        var guild = await client.GetGuildAsync(args.GuildId).ConfigureAwait(false);
                        var user  = guild.GetUser(client.CurrentUser.Id);
                        await user.ModifyAsync(x => x.Nickname = name).ConfigureAwait(false);
                    }
                    else
                    {
                        Console.Title = name;
                    }
                });
                return(new Response[] { Response.CreateFromReact(Emojis.ThumbsUpUnicode) });
            }
            else
            {
                return(Response.CreateArrayFromString($"{Emojis.CrossSymbol} {languageHandler.GetPhrase(serverSettings.Language, "Error_BotOwnerOnly")}."));
            }
        }
Beispiel #3
0
        public override IList <Response> Execute(SenderSettings senderDetail, IMessageDetail args)
        {
            ServerSettings       serverSettings = senderDetail.ServerSettings;
            CommandMessageHelper command        = new CommandMessageHelper(serverSettings.CommandSymbol, args.Message);
            string requestStr = command.CommandDetail;
            ulong  requestedId;

            if (string.IsNullOrWhiteSpace(requestStr))
            {
                // Default to the user asking.
                requestedId = args.UserId;
            }
            else
            {
                // Parse a mention?
                if (requestStr.StartsWith("<@") && requestStr.EndsWith(">"))
                {
                    requestStr = requestStr.Substring("<@".Length, requestStr.Length - 3); // Minus 3 for <@nnnnn>
                }

                // Id?
                if (!ulong.TryParse(requestStr, out requestedId))
                {
                    // No, fail.
                    return(Response.CreateArrayFromString($"{Emojis.CrossSymbol} {languageHandler.GetPhrase(senderDetail.ServerSettings.Language, "Error_NoResults")}: {requestStr}"));
                }
            }

            if (client != null)
            {
                Task.Run(async() =>
                {
                    // From the id, determine if it's a user or server.
                    // Is it a server?
                    var candidateServer = await client.GetGuildAsync(requestedId).ConfigureAwait(false);
                    if (candidateServer != null)
                    {
                        await asyncResponder.SendResponseAsync(args, Response.CreateFromString($"{candidateServer.IconUrl}")).ConfigureAwait(false);
                    }

                    // Is it a channel?
                    IChannel candidateChannel = await client.GetDMChannelAsync(requestedId).ConfigureAwait(false);
                    if (candidateChannel != null)
                    {
                        await asyncResponder.SendResponseAsync(args, Response.CreateFromString($"{candidateChannel.GetGuild().IconUrl}")).ConfigureAwait(false);
                    }

                    // Is it a user?
                    IUser candidateUser = client.GetUser(requestedId);
                    if (candidateUser != null)
                    {
                        await asyncResponder.SendResponseAsync(args, Response.CreateFromString($"{candidateUser.GetAvatarUrl(ImageFormat.Auto, 2048)}")).ConfigureAwait(false);
                    }
                });
            }
            return(new Response[] { Response.WaitForAsync });
        }