Ejemplo n.º 1
0
        public static RoleLevel GetRole(this IGuildUser user, IBotConfiguration botConfiguration, IGuildConfiguration guildConfiguration)
        {
            if (user.Id == botConfiguration.GlobalAdminId)
            {
                return(RoleLevel.GlobalAdministrator);
            }

            if (user.GuildPermissions.Administrator)
            {
                return(RoleLevel.GuildAdministrator);
            }

            // get a list of guild roles
            var roles = guildConfiguration.Roles
                        .OrderByDescending(r => (int)r.Level);

            foreach (var role in roles)
            {
                ulong guildRoleId = role.RoleId;
                if (user.RoleIds.Any(roleId => roleId == guildRoleId))
                {
                    return(role.Level);
                }
            }
            return(RoleLevel.None);
        }
Ejemplo n.º 2
0
 public CommandModuleBase(IDiscordClient discordClient, IDiscordBot discordBot, IServiceProvider serviceProvider, IBotConfiguration botConfiguration)
 {
     DiscordClient    = discordClient;
     DiscordBot       = discordBot;
     BotConfiguration = botConfiguration;
     ServiceProivder  = serviceProvider;
 }
Ejemplo n.º 3
0
 public Bot()
 {
     this.client   = new DiscordSocketClient();
     this.commands = new CommandService();
     this.services = BotServiceLocator.Resolver;
     this.config   = (IBotConfiguration)services.GetService(typeof(IBotConfiguration));
 }
Ejemplo n.º 4
0
        public ReminderService(DiscordSocketClient discordSocketClient, IBotConfiguration botConfiguration)
            : base(discordSocketClient, botConfiguration)
        {
            double interval = 1000 * 15;

            InitializeTimer(interval, true);
        }
Ejemplo n.º 5
0
 public GuildCommandModuleBase(IDiscordClient discordClient, IDiscordBot discordBot, IServiceProvider serviceProvider, IBotConfiguration botConfiguration)
 {
     _discordClient    = discordClient;
     _discordBot       = discordBot;
     _botConfiguration = botConfiguration;
     _serviceProvider  = serviceProvider;
 }
Ejemplo n.º 6
0
 public GameRotationService(DiscordShardedClient client, IBotConfiguration config)
 {
     _client = client;
     _config = config;
     _rng    = new DaveRNG();
     _t      = new Timer(NextPlayingStatus, null, 30000, 30000);
 }
Ejemplo n.º 7
0
 public ChatApiServiceClient(IBotConfiguration configuration)
 {
     this._configuration = configuration;
     this._httpClient    = new HttpClient {
         BaseAddress = new Uri(configuration.ServicesUrl)
     };
 }
Ejemplo n.º 8
0
 public DSharpPlusDiscord(IBotConfiguration botConfiguration, EntityConvertor entityConvertor, IServiceProvider services, ILanguageProvider lang)
 {
     _botConfiguration = botConfiguration;
     _services         = services;
     _entityConvertor  = entityConvertor;
     _lang             = lang;
 }
        public string MakeInfoLine(PokemonInfo info, IBotConfiguration config, ulong guildId, int paddingSize = 0)
        {
            var lineFormat = Language.Formats["infoLine"];// "\n{0}: {7}Tier={1} BossCP={2:#,##0} MinCP={3:#,##0} MaxCP={4:#,##0} CatchRate={5}%{6}";
            var padding    = 0;

            if (paddingSize > 0)
            {
                padding = paddingSize - info.BossNameFormatted.Length;
            }

            var allAliases = new List <string>(info.Aliases);

            if (config.GetServerConfig(guildId, ChatTypes.Discord).PokemonAliases.ContainsKey(info.Id))
            {
                allAliases.AddRange(config.GetServerConfig(guildId, ChatTypes.Discord).PokemonAliases[info.Id]);
            }

            return(string.Format(lineFormat,
                                 info.BossNameFormatted,
                                 new String(' ', padding),
                                 info.Tier,
                                 info.BossCP.ToString() + (info.BossCP < 9999 ? " " : ""),
                                 info.MinCP.ToString() + (info.MinCP < 999 ? " " : ""),
                                 info.MaxCP.ToString() + (info.MaxCP < 999 ? " " : ""),
                                 info.CatchRate * 100,
                                 allAliases.Count == 0 ? "" : Language.Strings["aliases"] + ": " + string.Join(",", allAliases)
                                 ));
        }
 public TranslationBotService(IBotConfiguration botConfiguration,
                              IUnitOfWork unitOfWork,
                              ITranslationService translationService)
 {
     _botConfiguration  = botConfiguration;
     UnitOfWork         = unitOfWork;
     TranslationService = translationService;
 }
Ejemplo n.º 11
0
 public CommandHandler(IDiscord discord, CommandService commandService, IServiceProvider services, ILogWriter logger, EntityConvertor convertor, IBotConfiguration botConfig)
 {
     _discord        = discord;
     _commandService = commandService;
     _services       = services;
     _logger         = logger;
     _convertor      = convertor;
     _botConfig      = botConfig;
 }
Ejemplo n.º 12
0
 public DSharpPlusDiscord(
     IBotConfiguration botConfiguration,
     EntityConvertor entityConvertor,
     IServiceProvider services)
 {
     _botConfiguration = botConfiguration;
     _services         = services;
     _entityConvertor  = entityConvertor;
 }
Ejemplo n.º 13
0
 public CommandHandler(IDiscord discord, IServiceProvider services, ILogWriter logger, EntityConvertor convertor, IBotConfiguration botConfig, ICommandProcessor commandProcessor)
 {
     _discord          = discord;
     _commandService   = new CommandService();
     _services         = services;
     _logger           = logger;
     _convertor        = convertor;
     _botConfig        = botConfig;
     _commandProcessor = commandProcessor;
 }
Ejemplo n.º 14
0
        // Public members

        public HelpService(
            IBotConfiguration botConfiguration,
            IServiceProvider serviceProvider,
            global::Discord.Commands.CommandService commandService
            )
        {
            _botConfiguration = botConfiguration;
            _serviceProvider  = serviceProvider;
            _commandService   = commandService;
        }
Ejemplo n.º 15
0
 public MiunieDiscordClient(IBotConfiguration botConfig)
 {
     Client = new DiscordClient(new DiscordConfiguration
     {
         Token                 = botConfig.GetBotToken(),
         TokenType             = TokenType.Bot,
         AutoReconnect         = true,
         LogLevel              = LogLevel.Info,
         UseInternalLogHandler = false
     });
 }
Ejemplo n.º 16
0
 public DiscordBot(IServiceCollection services)
 {
     ConfigureServices(services);
     ServiceProvider  = services.BuildServiceProvider();
     BotConfiguration = ServiceProvider.GetService <IBotConfiguration>();
     UserTracker      = ServiceProvider.GetService <IUserTrackerService>();
     Client           = ServiceProvider.GetService <IDiscordClient>() as DiscordSocketClient;
     Logger           = ServiceProvider.GetService <ILogger>();
     Commands         = ServiceProvider.GetService <CommandService>();
     CardStackManager = ServiceProvider.GetService <ICardStackManager>();
 }
Ejemplo n.º 17
0
        public CommandHandler(DiscordShardedClient client, CommandService commandService, IBotConfiguration config, DaveBot bot)
        {
            _client         = client;
            _commandService = commandService;
            _config         = config;
            _bot            = bot;

            _log = LogManager.GetCurrentClassLogger();

            DefaultPrefix = config.DefaultPrefix;
        }
        public IChatEmbed GetHelpEmbed(IBotConfiguration config, bool admin)
        {
            var embed = new DiscordChatEmbed();

            string info = $"*{Language.Strings["helpParenthesis"]}*";

            if (admin)
            {
                info += $"\n\\**{Language.Strings["helpAdmin"]}*";
            }

            embed.AddField($"__**{Language.Strings["helpCommands"]}**__", info);

            embed.AddField(string.Format("{0}__r__aid [pokemon] [time left] [location]", config.Prefix), Language.Strings["helpRaid"]);
            embed.AddField(string.Format("{0}__j__oin [raid] [number]", config.Prefix), Language.Strings["helpJoin"]);
            embed.AddField(string.Format("{0}__un__join [raid]", config.Prefix), Language.Strings["helpUnJoin"]);
            embed.AddField(string.Format("{0}__d__elete [raid id]", config.Prefix), Language.Strings["helpDelete"]);
            embed.AddField(string.Format("{0}__m__erge [raid1] [raid2]", config.Prefix), Language.Strings["helpMerge"]);
            embed.AddField(string.Format("{0}__loc__ation [raid] [new location]", config.Prefix), Language.Strings["helpLocation"]);
            embed.AddField(string.Format("{0}__e__nd [raid] [new end time]", config.Prefix), Language.Strings["helpEnd"]);
            embed.AddField(string.Format("{0}__s__tart [raid] [start time]", config.Prefix), Language.Strings["helpStart"]);
            embed.AddField(string.Format("{0}__i__nfo [name]", config.Prefix), Language.Strings["helpInfo"]);
            embed.AddField(string.Format("{0}__h__elp", config.Prefix), Language.Strings["helpHelp"]);

            if (admin)
            {
                embed.AddField(string.Format("*{0}channel [name]", config.Prefix), string.Format(Language.Strings["helpChannel"], config.OutputChannel));
                embed.AddField(string.Format("*{0}nochannel", config.Prefix), Language.Strings["helpNoChannel"]);
                embed.AddField(string.Format("*{0}alias [pokemon] [alias]", config.Prefix), Language.Strings["helpAlias"]);
                embed.AddField(string.Format("*{0}removealias [pokemon] [alias]", config.Prefix), Language.Strings["helpRemoveAlias"]);
                embed.AddField(string.Format("*{0}pin [channel name]", config.Prefix), Language.Strings["helpPin"]);
                embed.AddField(string.Format("*{0}unpin [channel name]", config.Prefix), Language.Strings["helpUnPin"]);
                embed.AddField(string.Format("*{0}pinall", config.Prefix), Language.Strings["helpPinAll"]);
                embed.AddField(string.Format("*{0}unpinall", config.Prefix), Language.Strings["helpUnPinAll"]);
                embed.AddField(string.Format("*{0}pinlist", config.Prefix), Language.Strings["helpPinList"]);
                embed.AddField(string.Format("*{0}mute [channel name]", config.Prefix), Language.Strings["helpMute"]);
                embed.AddField(string.Format("*{0}unmute [channel name]", config.Prefix), Language.Strings["helpUnMute"]);
                embed.AddField(string.Format("*{0}muteall", config.Prefix), Language.Strings["helpMuteAll"]);
                embed.AddField(string.Format("*{0}unmuteall", config.Prefix), Language.Strings["helpUnMuteAll"]);
                embed.AddField(string.Format("*{0}mutelist", config.Prefix), Language.Strings["helpMuteList"]);
                embed.AddField(string.Format("*{0}timezone [gmt offset]", config.Prefix), Language.Strings["helpTimezone"]);
                embed.AddField(string.Format("*{0}culture [culture]", config.Prefix), Language.Strings["helpCulture"]);
                embed.AddField(string.Format("*{0}city [city]", config.Prefix), Language.Strings["helpCity"]);
                embed.AddField(string.Format("*{0}channelcity [channel name] [city]", config.Prefix), Language.Strings["helpChannelCity"]);
                embed.AddField(string.Format("*{0}cities", config.Prefix), Language.Strings["helpCities"]);
                embed.AddField(string.Format("*{0}place", config.Prefix), Language.Strings["helpPlace"]);
                embed.AddField(string.Format("*{0}deleteplace", config.Prefix), Language.Strings["helpDeletePlace"]);
                embed.AddField(string.Format("*{0}places", config.Prefix), Language.Strings["helpPlaces"]);
                embed.AddField(string.Format("*{0}clearplaces", config.Prefix), Language.Strings["helpClearPlaces"]);
            }

            return(embed);
        }
 public ForwardMessageHandler(
     IKernel kernel,
     ILogger logger,
     IAdminChatValidator IAdminChatManager,
     ISessionManager sessionManager,
     IBotConfiguration config,
     IAdminChatManager adminChatManager)
     : base(kernel, logger, IAdminChatManager, sessionManager)
 {
     _adminChatManager = adminChatManager;
     _config           = config;
 }
Ejemplo n.º 20
0
        public string GetSyntax(CommandInfo cmd, IBotConfiguration botConfig, IGuildConfiguration guildConfiguration = null)
        {
            char prefix = botConfig.DirectMessageCommandPrefix;

            if (guildConfiguration != null)
            {
                prefix = guildConfiguration.CommandPrefix;
            }

            return(Syntax
                   .Replace("{prefix}", prefix.ToString(), StringComparison.OrdinalIgnoreCase)
                   .Replace("{command}", cmd.Name, StringComparison.OrdinalIgnoreCase));
        }
        public BotCommandHandler(IChatMessageHandler handler, IChatMessage message, MessageParser parser)
        {
            Handler = handler;
            Message = message;
            Parser = parser;

            Config = Handler.Config;
            Command = new List<string>(Message.Content.ToLower().Replace("  ", " ").Substring(Config.Prefix.Length).Split(' '));
            Command.Remove("");
            switch (message.ChatType)
            {
                case ChatTypes.Discord:
                    Output = new DiscordMessageOutput();
                    break;
            }

            GuildConfig = Config.GetServerConfig(message.Server.Id, message.ChatType);
        }
Ejemplo n.º 22
0
        public CommandService(
            IBotConfiguration configuration,
            IServiceProvider serviceProvider,
            IHelpService helpService,
            IResponsiveMessageService responsiveMessageService,
            DiscordSocketClient discordClient,
            global::Discord.Commands.CommandService commandService
            )
        {
            this.configuration            = configuration;
            this.serviceProvider          = serviceProvider;
            this.helpService              = helpService;
            this.responsiveMessageService = responsiveMessageService;
            this.discordClient            = discordClient;
            DiscordCommandService         = commandService;

            this.discordClient.MessageReceived    += OnMessageReceivedAsync;
            DiscordCommandService.CommandExecuted += OnCommandExecutedAsync;
        }
Ejemplo n.º 23
0
        public async Task Start(IBotConfiguration botConfiguration)
        {
            _botConfiguration = botConfiguration;
            Name = _botConfiguration.UserName;
            ConnectionCredentials credentials = new ConnectionCredentials(_botConfiguration.UserName, _botConfiguration.OAuthToken);

            bossFightGame = new BossFightGame();
            client        = new TwitchClient();
            client.Initialize(credentials, _botConfiguration.Channel);

            client.OnConnected       += onConnected;
            client.OnJoinedChannel   += onJoinedChannel;
            client.OnMessageReceived += onMessageRecieved;
            client.OnLeftChannel     += onLeftChannel;
            client.OnDisconnected    += onDisconnected;

            client.Connect();
            await RegisterCommands();
        }
Ejemplo n.º 24
0
        public BotManager(
            IKernel kernel,
            IBotConfiguration config,
            IAdminChatManager adminChatManager,
            IPipeLine <IUpdateHandler, Update> updatePipeLine,
            ILogger logger,
            CommandMessageHandler commandMessageHandler)
        {
            _config                = config;
            _logger                = logger;
            _adminChatManager      = adminChatManager;
            _updatePipeLine        = updatePipeLine;
            _commandMessageHandler = commandMessageHandler;

            Telegram = string.IsNullOrEmpty(_config.Proxy.Host)
                ? new TelegramBotClient(_config.ApiToken)
                : new TelegramBotClient(_config.ApiToken, new WebProxy(_config.Proxy.Host, _config.Proxy.Port));
            _receiver = new QueuedUpdateReceiver(Telegram);
            Telegram.OnReceiveError        += Telegram_OnReceiveError;
            Telegram.OnReceiveGeneralError += Telegram_OnReceiveGeneralError;
        }
Ejemplo n.º 25
0
 public PreconditionCheckStep(ICommandPipelineStep step, IBotConfiguration config)
     : base(step)
 {
     _config = config;
 }
        /// <summary>
        /// Uses google geocoding API to get the lat & long from a full location string
        /// </summary>
        /// <param name="location"></param>
        /// <param name="channel"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        public async Task <GeoCoordinate> GetLocationLatLong(string location, IChatChannel channel, IBotConfiguration config)
        {
            if (string.IsNullOrEmpty(config.GoogleApiKey))
            {
                return(null);
            }

            var url = string.Format(Language.Formats["googleMapGeocodeApi"], location, config.GoogleApiKey);

            var     request = (HttpWebRequest)WebRequest.Create(url);
            dynamic fullresult;

            using (var response = (HttpWebResponse)await request.GetResponseAsync())
            {
                using (var responseStream = response.GetResponseStream())
                {
                    using (var reader = new StreamReader(responseStream))
                    {
                        fullresult = JsonConvert.DeserializeObject <dynamic>(reader.ReadToEnd());
                    }
                }
            }
            if (fullresult.results != null && ((JArray)fullresult.results).Count() > 0)
            {
                var lat = ((JValue)fullresult.results[0].geometry.location.lat).ToObject <double>();
                var lng = ((JValue)fullresult.results[0].geometry.location.lng).ToObject <double>();

                return(new GeoCoordinate(lat, lng));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 27
0
 public GuildService(DiscordSocketClient discordSocketClient, IBotConfiguration botConfiguration)
 {
     _discordClient    = discordSocketClient;
     _botConfiguration = botConfiguration;
     RegisterForEvents();
 }
Ejemplo n.º 28
0
 public LlectroBotCardContext(IDiscordClient discordClient, IGuild guild, IMessageChannel channel, IUser user, IUserMessage message, IBotConfiguration botConfiguration, IGuildConfiguration guildConfiguration) : base(discordClient, guild, channel, user, message)
 {
     BotConfiguration   = botConfiguration;
     GuildConfiguration = guildConfiguration;
 }
Ejemplo n.º 29
0
 public TextPortalCmds(IBotConfiguration config, TextPortalService textportals)
 {
     _config      = config;
     _textportals = textportals;
 }
Ejemplo n.º 30
0
 public UserTrackerService(DiscordSocketClient discordSocketClient, IBotConfiguration botConfiguration)
     : base(discordSocketClient, botConfiguration)
 {
     _guilds = ReadJson().GetAwaiter().GetResult();
 }