示例#1
0
        // forwards dms
        public async Task LateExecute(DiscordSocketClient client, IGuild guild, IUserMessage msg)
        {
            if (msg.Channel is IDMChannel && ForwardDMs && ownerChannels.Length > 0)
            {
                var title = _strings.GetText("Administration".ToLowerInvariant(),
                                             "dm_from",
                                             _localization.DefaultCultureInfo) +
                            $" [{msg.Author}]({msg.Author.Id})";

                var attachamentsTxt = _strings.GetText("Administration".ToLowerInvariant(),
                                                       "attachments",
                                                       _localization.DefaultCultureInfo);

                var toSend = msg.Content;

                if (msg.Attachments.Count > 0)
                {
                    toSend += $"\n\n{Format.Code(attachamentsTxt)}:\n" +
                              string.Join("\n", msg.Attachments.Select(a => a.ProxyUrl));
                }

                if (ForwardDMsToAllOwners)
                {
                    var allOwnerChannels = await Task.WhenAll(ownerChannels
                                                              .Select(x => x.Value))
                                           .ConfigureAwait(false);

                    foreach (var ownerCh in allOwnerChannels.Where(ch => ch.Recipient.Id != msg.Author.Id))
                    {
                        try
                        {
                            await ownerCh.SendConfirmAsync(toSend, title).ConfigureAwait(false);
                        }
                        catch
                        {
                            _log.Warn("Can't contact owner with id {0}", ownerCh.Recipient.Id);
                        }
                    }
                }
                else
                {
                    var firstOwnerChannel = await ownerChannels[0];
                    if (firstOwnerChannel.Recipient.Id != msg.Author.Id)
                    {
                        try
                        {
                            await firstOwnerChannel.SendConfirmAsync(toSend, title).ConfigureAwait(false);
                        }
                        catch
                        {
                            // ignored
                        }
                    }
                }
            }
        }
        public async Task <bool> TryExecuteEarly(DiscordSocketClient client, IGuild guild, IUserMessage msg, bool realExecution = true)
        {
            var cr = TryGetCustomReaction(msg);

            if (cr == null)
            {
                return(false);
            }
            if (!realExecution)
            {
                return(true);
            }

            try {
                if (guild is SocketGuild sg)
                {
                    var pc = _perms.GetCache(guild.Id);
                    if (!pc.Permissions.CheckPermissions(msg, cr.Trigger, "ActualCustomReactions", out var index))
                    {
                        if (!pc.Verbose)
                        {
                            return(true);
                        }
                        var returnMsg = _strings.GetText("permissions", "trigger", guild.Id, index + 1, Format.Bold(pc.Permissions[index].GetCommand(_cmd.GetPrefix(guild), sg)));
                        try { await msg.Channel.SendErrorAsync(returnMsg).ConfigureAwait(false); } catch { }
                        _log.Info(returnMsg);
                        return(true);
                    }
                }
                await cr.Send(msg, _client, this).ConfigureAwait(false);

                if (!cr.AutoDeleteTrigger)
                {
                    return(true);
                }
                try { await msg.DeleteAsync().ConfigureAwait(false); } catch { }
                return(true);
            } catch (Exception ex) {
                _log.Warn("Sending CREmbed failed");
                _log.Warn(ex);
            }
            return(false);
        }
示例#3
0
        public async Task <bool> TryBlockLate(DiscordSocketClient client, IUserMessage msg, IGuild guild, IMessageChannel channel, IUser user, string moduleName, string commandName)
        {
            await Task.Yield();

            if (!(guild is SocketGuild socketGuild))
            {
                return(false);
            }
            var resetCommand = commandName == "resetperms";

            var pc = GetCache(guild.Id);

            if (!resetCommand && !pc.Permissions.CheckPermissions(msg, commandName, moduleName, out var index))
            {
                if (!pc.Verbose)
                {
                    return(true);
                }
                try { await channel.SendErrorAsync(_strings.GetText("permissions", "trigger", guild.Id, index + 1, pc.Permissions[index].GetCommand(_cmd.GetPrefix(guild), socketGuild))).ConfigureAwait(false); } catch { }
                return(true);
            }


            if (moduleName != "Permissions")
            {
                return(false);
            }
            var roles = (user as SocketGuildUser)?.Roles ?? ((IGuildUser)user).RoleIds.Select(guild.GetRole).Where(x => x != null);

            if (roles.Any(r => string.Equals(r.Name.Trim(), pc.PermRole.Trim(), StringComparison.InvariantCultureIgnoreCase)) || user.Id == ((IGuildUser)user).Guild.OwnerId)
            {
                return(false);
            }
            var returnMsg = $"You need the **{pc.PermRole}** role in order to use permission commands.";

            if (!pc.Verbose)
            {
                return(true);
            }
            try { await channel.SendErrorAsync(returnMsg).ConfigureAwait(false); } catch { }
            return(true);
        }
 private string GetText(string key, ulong?guildId, params string[] replacements)
 => _ss.GetText("verification", key, guildId, replacements);
示例#5
0
 private string GetText(string key, params object[] replacements)
 => _strings.GetText("utility", key, _guild.Id, replacements);
 private string GetText(IGuildChannel ch, string key, params object[] rep)
 => _strings.GetText("games", key, ch.GuildId, rep);
示例#7
0
 private string GetText(string text, IGuild guild, params object[] replacements) =>
 _strings.GetText("help", text, guild?.Id, replacements);
示例#8
0
 private string GetText(string key, ulong?guildId, params object[] replacements)
 => _ss.GetText("forum", key, guildId, replacements);
示例#9
0
 private string GetText(IGuild guild, string key, params object[] replacements)
 => _strings.GetText("administration", key, guild.Id, replacements);
        private Task UserUpdatedEventHandler(SocketUser user, SocketVoiceState before, SocketVoiceState after)
        {
            if (!(user is SocketGuildUser guildUser))
            {
                return(Task.CompletedTask);
            }

            var botUserPerms = guildUser.Guild.CurrentUser.GuildPermissions;

            if (before.VoiceChannel == after.VoiceChannel)
            {
                return(Task.CompletedTask);
            }

            using var uow = _db.UnitOfWork;
            var gc = uow.GuildConfigs.For(guildUser.Guild.Id);

            if (!gc.VoicePlusTextEnabled)
            {
                return(Task.CompletedTask);
            }

            var _ = Task.Run(async() => {
                try {
                    if (!botUserPerms.ManageChannels || !botUserPerms.ManageRoles)
                    {
                        try {
                            await guildUser.Guild.Owner.SendErrorAsync(_strings.GetText("administration", "vt_exit", guildUser.Guild.Id, Format.Bold(guildUser.Guild.Name))).ConfigureAwait(false);
                        } catch { }

                        gc.VoicePlusTextEnabled = false;

                        await uow.SaveChangesAsync().ConfigureAwait(false);
                    }
                    else
                    {
                        var semaphore = _guildLockObjects.GetOrAdd(guildUser.Guild.Id, (key) => new SemaphoreSlim(1, 1));

                        try {
                            await semaphore.WaitAsync().ConfigureAwait(false);

                            var beforeVch = before.VoiceChannel;
                            if (beforeVch != null)
                            {
                                var beforeRoleName = GetRoleName(beforeVch);
                                var beforeRole     = guildUser.Guild.Roles.FirstOrDefault(x => x.Name.Equals(beforeRoleName, StringComparison.OrdinalIgnoreCase));
                                if (beforeRole != null)
                                {
                                    _log.Info($"Removing role {beforeRoleName} from user {guildUser.Username}");
                                    await guildUser.RemoveRoleAsync(beforeRole).ConfigureAwait(false);
                                    await Task.Delay(200).ConfigureAwait(false);
                                }
                            }

                            var afterVch = after.VoiceChannel;
                            if (afterVch != null && guildUser.Guild.AFKChannel?.Id != afterVch.Id)
                            {
                                var roleToAdd = guildUser.Guild.Roles.FirstOrDefault(x => x.Name.Equals(GetRoleName(afterVch), StringComparison.OrdinalIgnoreCase));

                                if (roleToAdd != null)
                                {
                                    _log.Info($"Adding role {roleToAdd.Name} to user {guildUser.Username}");
                                    await guildUser.AddRoleAsync(roleToAdd).ConfigureAwait(false);
                                }
                            }
                        } finally {
                            semaphore.Release();
                        }
                    }
                } catch (Exception ex) {
                    _log.Warn(ex);
                }
            });

            return(Task.CompletedTask);
        }
 private string GetText(string key, params object[] replacements)
 => _stringService.GetText("verification", key, GuildUser.GuildId, replacements);