Ejemplo n.º 1
0
 public BotController(ICredentials botCredentials, IDiscordBot bot, BotEvents botEvents, ILogger logger)
 {
     _botCredentials = botCredentials;
     _bot            = bot;
     _botEvents      = botEvents;
     _logger         = logger;
 }
Ejemplo n.º 2
0
 public GuildCommandModuleBase(IDiscordClient discordClient, IDiscordBot discordBot, IServiceProvider serviceProvider, IBotConfiguration botConfiguration)
 {
     _discordClient    = discordClient;
     _discordBot       = discordBot;
     _botConfiguration = botConfiguration;
     _serviceProvider  = serviceProvider;
 }
Ejemplo n.º 3
0
 public CommandModuleBase(IDiscordClient discordClient, IDiscordBot discordBot, IServiceProvider serviceProvider, IBotConfiguration botConfiguration)
 {
     DiscordClient    = discordClient;
     DiscordBot       = discordBot;
     BotConfiguration = botConfiguration;
     ServiceProivder  = serviceProvider;
 }
Ejemplo n.º 4
0
 public DiscordCommandContext(IDiscordClient client, IUserMessage message, IGuildConfiguration guildConfiguration, IDiscordBot discordBot, IGuildUser guildUser)
     : base(client, message)
 {
     GuildConfiguration = guildConfiguration;
     DiscordBot         = discordBot;
     GuildUser          = guildUser;
 }
Ejemplo n.º 5
0
 public DeployPublisher(IDiscordBot bot, IOctopusClientFactory octopusClientFactory, OctopusServerEndpoint octopusServerEndpoint, ILogger <DeployPublisher> logger)
 {
     this._bot = bot ?? throw new ArgumentNullException(nameof(bot));
     this._octopusClientFactory  = octopusClientFactory ?? throw new ArgumentNullException(nameof(octopusClientFactory));
     this._octopusServerEndpoint = octopusServerEndpoint ?? throw new ArgumentNullException(nameof(octopusServerEndpoint));
     this._logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Ejemplo n.º 6
0
        protected override async Task <bool> ExecuteCommand(IDiscordBot bot, SocketMessage message, Abstractions.Model.ApplicationUser user, ApplicationDbContext context, DiceOption option)
        {
            var amountArgs = option.Amount;
            var funDice    = string.IsNullOrEmpty(amountArgs);
            var random     = new Random();
            var nextRoll   = random.Next(1, 100);

            var eb = new EmbedBuilder {
                Title = "Dice Roll"
            };
            var diceResult = new StringBuilder($"{message.Author.Mention} rolled {nextRoll} on the percentile dice, and you ");
            var win        = nextRoll >= 55;

            diceResult.Append(win ? "won" : "lost");

            if (!funDice)
            {
                var coinItem = user.Bank.GetAmount(995);

                var amountNumber = StackFormatter.StackSizeToQuantity(option.Amount);
                if (amountNumber <= 0)
                {
                    return(false);
                }

                if (coinItem < (ulong)amountNumber)
                {
                    await message.Channel.SendMessageAsync($"{message.Author.Mention} does not have {amountArgs} coins to gamble.");

                    return(false);
                }

                if (win)
                {
                    user.Bank.Add(new Item(995, amountNumber));
                }
                else
                {
                    user.Bank.Remove(new Item(995, amountNumber));
                }

                await context.SaveChangesAsync();

                diceResult.Append($" {StackFormatter.QuantityToRSStackSize((long) amountNumber)} GP");
            }
            user.Bank.UpdateRequired = true;
            diceResult.Append(".");


            eb.WithDescription(diceResult.ToString());
            eb.WithThumbnailUrl("https://i.imgur.com/sySQkSX.png");
            eb.WithColor(Color.Orange);

            if (message != null)
            {
                await message.Channel.SendMessageAsync(string.Empty, embed : eb.Build());
            }
            return(true);
        }
Ejemplo n.º 7
0
 public Worker(ILogger <Worker> logger, IOptions <ConfigSettings> settings, IDiscordBot discordBot,
               DiscordSocketClient discordSocketClient, IServiceScopeFactory serviceProvider)
 {
     _logger              = logger;
     _discordBot          = discordBot;
     _discordSocketClient = discordSocketClient;
     _serviceProvider     = serviceProvider;
     _settings            = settings.Value;
 }
Ejemplo n.º 8
0
        public BotEvents(ILogger logger, IDiscordBot bot, IHubContext <BotHub> botHubContext, IHubContext <ChatHub> chatHubContext)
        {
            _botHubContext  = botHubContext;
            _chatHubContext = chatHubContext;

            logger.OnLog             += OnNewLog;
            bot.OnConnectedChanged   += BotOnConnectedChanged;
            bot.OnBotAccountChanged  += OnBotAccountChanged;
            bot.OnBotReceivedMessage += OnBotReceivedMessage;
        }
Ejemplo n.º 9
0
 public PlanEvent(IDataAccess dataAccess, IDiscordBot discordBot, IGitHubFileReader fileReader,
                  IPlanZoomMeeting planZoomMeeting, EmailContentBuilder emailBuilder, NewsletterHtmlBuilder htmlBuilder)
 {
     this.fileReader      = fileReader;
     this.dataAccess      = dataAccess;
     this.planZoomMeeting = planZoomMeeting;
     this.htmlBuilder     = htmlBuilder;
     this.emailBuilder    = emailBuilder;
     this.discordBot      = discordBot;
 }
Ejemplo n.º 10
0
 public Worker(ILogger <Worker> logger, IOptions <ConfigSettings> settings, IDiscordBot discordBot,
               DiscordSocketClient discordSocketClient,
               IStreamAnnouncer streamAnnouncer, CommandHandler commandHandler)
 {
     _logger              = logger;
     _discordBot          = discordBot;
     _discordSocketClient = discordSocketClient;
     _streamAnnouncer     = streamAnnouncer;
     _commandHandler      = commandHandler;
     _configSettings      = settings.Value;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Constructs the <see cref="StartupService"/>
 /// </summary>
 public StartupService(DiscordBotServiceContainer services,
                       IConfigurationRoot config,
                       DiscordSocketClient client,
                       CommandServiceEx commands,
                       IDiscordBot discordBot)
 {
     Services   = services;
     Client     = client;
     Commands   = commands;
     DiscordBot = discordBot;
 }
Ejemplo n.º 12
0
        protected override async Task <bool> ExecuteCommand(IDiscordBot bot, SocketMessage message, ApplicationUser user, ApplicationDbContext context, ShopBuyOption option)
        {
            var updated = await _shopManager.Buy(user, message, option);

            if (option.Confirm.GetValueOrDefault() && updated)
            {
                user.Bank.UpdateRequired = true;
                SaveChanges = true;
            }
            return(true);
        }
Ejemplo n.º 13
0
        public async Task <bool> Parse(IDiscordBot bot, SocketMessage message, string[] args)
        {
            var parsedCommand = Parser.Default.ParseArguments(args, OptionType);
            var result        = false;
            await parsedCommand
            .MapResult(async options =>
                       await ExecuteCommandInner(bot, message, (IOptionsBase)options),
                       error => ErrorText(parsedCommand, message, error));

            return(result);
        }
Ejemplo n.º 14
0
 protected override async Task <bool> ExecuteCommand(IDiscordBot bot, SocketMessage message, ApplicationUser user, ApplicationDbContext context, BankOption option)
 {
     using (var bankWidgetImage =
                await _bankWidget.GetWidgetAsync(
                    new BankWidgetOptions {
         Options = option, Title = $"Bank of {message.Author}", Items = user.Items.ToList()
     }))
     {
         await message.Channel.SendFileAsync(bankWidgetImage, "image.png", string.Empty);
     }
     return(true);
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Constructs the <see cref="DiscordStartup"/> instance to run the bot.
 /// </summary>
 /// <param name="args">The command line arguments.</param>
 /// <param name="discordBot">The discord bot to run.</param>
 /// <param name="allowMultipleInstances">
 /// True if multiple instances of the Discord Bot token can run at the same time.
 /// </param>
 private DiscordStartup(string[] args, IDiscordBot discordBot, bool allowMultipleInstances)
 {
     this.args                   = args;
     this.discordBot             = discordBot;
     this.allowMultipleInstances = allowMultipleInstances;
     if (args.Length > 0 && args[0] == DaemonArgument)
     {
         isRunningFromDaemon = true;
         // Be nice and remove the daemon argument.
         this.args = args.Skip(1).ToArray();
     }
     discordBot.StartupError += OnStartupError;
 }
Ejemplo n.º 16
0
 public SigninModel(
     IConfiguration configuration,
     SignInManager <ApplicationUser> signInManager,
     UserManager <ApplicationUser> userManager,
     ILogger <SigninModel> logger,
     IHttpClientFactory clientFactory,
     IDiscordBot discordBot)
 {
     _configuration = configuration;
     _signInManager = signInManager;
     _userManager   = userManager;
     _logger        = logger;
     _clientFactory = clientFactory;
     _discordBot    = discordBot;
 }
Ejemplo n.º 17
0
        protected override async Task <bool> ExecuteCommand(IDiscordBot bot, SocketMessage message, Abstractions.Model.ApplicationUser user, ApplicationDbContext context, GpOption option)
        {
            var coins = user.Bank.GetAmount(995);

            var eb = new EmbedBuilder {
                Title = "GP Count"
            };

            eb.WithDescription($"@{message.Author} has {coins} gp.");
            eb.WithThumbnailUrl("https://runescape.wiki/images/6/63/Coins_detail.png");
            eb.WithColor(Color.Gold);

            await message.Channel.SendMessageAsync(string.Empty, embed : eb.Build());

            return(true);
        }
Ejemplo n.º 18
0
        public Task <bool> ParseCommand(IDiscordBot bot, SocketMessage arg, params string[] args)
        {
            using (var scope = _serviceProvider.CreateScope())
            {
                var commands      = scope.ServiceProvider.GetRequiredService <IEnumerable <ICommand> >();
                var parsedCommand = commands
                                    .FirstOrDefault(command =>
                                                    command.CommandName.Equals(args[0], StringComparison.InvariantCultureIgnoreCase));
                var commandExists = parsedCommand != null;

                if (commandExists)
                {
                    return(parsedCommand.Parse(bot, arg, args));
                }
                else
                {
                    var isHelp = args[0].Equals("help", StringComparison.InvariantCultureIgnoreCase);
                    if (isHelp)
                    {
                        var helpParsed = Parser.Default.ParseArguments(args, commands.Select(t => t.OptionType).ToArray());
                        helpParsed.WithNotParsed(t =>
                        {
                            var helpText = HelpText.AutoBuild(helpParsed, helpText =>
                            {
                                helpText.Copyright                     = string.Empty;
                                helpText.Heading                       = string.Empty;
                                helpText.MaximumDisplayWidth           = 296;
                                helpText.AddDashesToOption             = true;
                                helpText.AdditionalNewLineAfterOption  = true;
                                helpText.AddNewLineBetweenHelpSections = true;
                                return(HelpText.DefaultParsingErrorsHandler(helpParsed, helpText));
                            }, 80);
                            var eb = new EmbedBuilder {
                                Title = $"Command Help"
                            };
                            eb.WithDescription(helpText.ToString());
                            eb.WithThumbnailUrl("https://static.wikia.nocookie.net/runescape2/images/1/10/Security_book_detail.png");
                            eb.WithColor(Color.Purple);
                            arg.Channel.SendMessageAsync(string.Empty, embed: eb.Build());
                        });
                    }
                }
                return(Task.FromResult(false));
            }
        }
Ejemplo n.º 19
0
        protected override async Task <bool> ExecuteCommand(IDiscordBot bot, SocketMessage message, ApplicationUser user, ApplicationDbContext context, StatusOption option)
        {
            var taskName = user.CurrentTask.TaskName;

            if (!user.CurrentTask.Notified && DateTime.Now > user.CurrentTask.UnlockTime)
            {
                await message.Channel.SendMessageAsync($"{user.Mention} is on the way back from {taskName}");
            }
            else if (user.CurrentTask.Notified || (!user.CurrentTask.Notified && DateTime.Now > user.CurrentTask.UnlockTime))
            {
                await message.Channel.SendMessageAsync($"{user.Mention} is doing nothing");
            }
            else
            {
                await message.Channel.SendMessageAsync($"{user.Mention} is currently {taskName}");
            }

            return(true);
        }
Ejemplo n.º 20
0
        protected async override Task <bool> ExecuteCommand(IDiscordBot bot, SocketMessage message, TOption option)
        {
            var userId = message.Author.Id.ToString();

            using (var context = _contextFactory.Create())
            {
                var user = await context.Users.AsQueryable()
                           .Include(t => t.Items)
                           .Include(t => t.Equipment)
                           .Include(t => t.CurrentTask)
                           .Include(t => t.SkillSet)
                           .ThenInclude(t => t.Skills)
                           .FirstOrDefaultAsync(t => t.Id == userId);

                if (user == null)
                {
                    await message.Channel.SendMessageAsync($"{message.Author} is not registered, please type +register.");

                    return(false);
                }

                user.Bank = new Inventory(BankConstants.Size, Inventory.StackMode.STACK_ALWAYS);
                user.Bank.CopyTo(user.Items.Select(t => t.Item));
                bool res = await ExecuteCommand(bot, message, user, context, option);

                if (user.Bank.UpdateRequired)
                {
                    await BankSaver.SaveBank(context, user);

                    SaveChanges = true;
                }

                if (SaveChanges)
                {
                    await context.SaveChangesAsync();

                    SaveChanges = false;
                }

                return(res);
            }
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Construcst the <see cref="ReliabilityService"/> with the specified configuration.
 /// </summary>
 public ReliabilityService(ReliabilityConfig reliabilityConfig,
                           DiscordSocketClient client,
                           IDiscordBot discordBot,
                           ILoggingService log)
 {
     Timeout          = reliabilityConfig.Timeout;
     AttemptReset     = reliabilityConfig.AttemptReset;
     DebugSeverity    = reliabilityConfig.DebugSeverity;
     InfoSeverity     = reliabilityConfig.InfoSeverity;
     CriticalSeverity = reliabilityConfig.CriticalSeverity;
     if (reliabilityConfig.Enabled)
     {
         this.client          = client;
         this.discordBot      = discordBot;
         this.log             = log;
         cancel               = new CancellationTokenSource();
         client.Connected    += OnConnectedAsync;
         client.Disconnected += OnDisconnectedAsync;
     }
 }
Ejemplo n.º 22
0
        protected override async Task <bool> ExecuteCommand(IDiscordBot bot, SocketMessage message, ApplicationUser user, ApplicationDbContext context, ShopViewOption option)
        {
            var shop = _shopManager.GetForName(option.Name);

            if (shop == null)
            {
                await message.Channel.SendMessageAsync($"Invalid shop name. Available shops: {_shopManager.GetNames()}");

                return(false);
            }

            using (var shopWidget =
                       await _shopWidget.GetWidgetAsync(
                           new ShopWidgetOptions {
                Title = shop.Name, Items = shop.Items
            }))
            {
                await message.Channel.SendFileAsync(shopWidget, "image.png", string.Empty);
            }
            return(true);
        }
Ejemplo n.º 23
0
        protected override async Task <bool> ExecuteCommand(IDiscordBot bot, SocketMessage message, ApplicationUser user, ApplicationDbContext context, SkillOption option)
        {
            if (user.CurrentTask != null && !user.CurrentTask.Notified)
            {
                await message.Channel.SendMessageAsync("Your minion is busy!");

                return(true);
            }

            var simulation = await _skillSimulator.SimulateTask(bot, user, message, option);

            if (simulation == null)
            {
                return(true);
            }

            simulation.Notified = false;
            user.CurrentTask.Copy(simulation);
            user.CurrentTask.Command = Parser.Default.FormatCommandLine(option);
            if (user.CurrentTask.ExpGains != null && user.CurrentTask.ExpGains.Any())
            {
                foreach (var expGains in user.CurrentTask.ExpGains)
                {
                    expGains.CurrentTaskId = user.CurrentTaskId;
                }
                context.AddRange(user.CurrentTask.ExpGains);
            }

            if (user.CurrentTask.Items != null && user.CurrentTask.Items.Any())
            {
                foreach (var item in user.CurrentTask.Items)
                {
                    item.CurrentTaskId = user.CurrentTaskId;
                }
                context.AddRange(user.CurrentTask.Items);
            }
            context.Update(user.CurrentTask);
            SaveChanges = true;
            return(true);
        }
Ejemplo n.º 24
0
        protected override async Task <bool> ExecuteCommand(IDiscordBot bot, SocketMessage message, ApplicationUser user, ApplicationDbContext context, GearOption option)
        {
            List <EquipmentItem> equipmentItems = user.Equipment.Where(t => t.EquipmentType.Equals(option.EquipmentType, StringComparison.InvariantCultureIgnoreCase))
                                                  .ToList();

            if (!EquipmentConstants.IsValidEquipmentType(option.EquipmentType))
            {
                await message.Channel.SendMessageAsync($"Invalid command equipment type {option.EquipmentType} from {message.Author}");

                return(false);
            }

            using (var equipmentWidget =
                       await _equipmentWidget.GetWidgetAsync(
                           new EquipmentWidgetOptions {
                Options = option, Items = equipmentItems
            }))
            {
                await message.Channel.SendFileAsync(equipmentWidget, "image.png", string.Empty);
            }
            return(true);
        }
Ejemplo n.º 25
0
        protected override async Task <bool> ExecuteCommand(IDiscordBot bot, SocketMessage message, RegisterOption option)
        {
            var userId = message.Author.Id;

            using (var dbContext = _dbContextFactory.Create())
            {
                var existingUser = dbContext.Users.FirstOrDefault(t => t.DiscordId == userId);
                if (existingUser != null)
                {
                    await message.Channel.SendMessageAsync($"{message.Author.Username} already has a registered user.");
                }
                else
                {
                    var skillSet = new SkillSet();
                    skillSet.Init();
                    var applicationUser = new ApplicationUser
                    {
                        DiscordId          = userId,
                        UserName           = message.Author.Username,
                        NormalizedUserName = message.Author.Username.ToUpper(),
                        Id           = userId.ToString(),
                        PasswordHash = "TestAtm",
                        SkillSet     = skillSet,
                        CurrentTask  = new CurrentTask {
                            Notified = true, UserId = userId.ToString(), UnlockTime = DateTime.MinValue
                        },
                        Mention = message.Author.Mention
                    };
                    dbContext.Add(applicationUser);

                    await dbContext.SaveChangesAsync();

                    await message.Channel.SendMessageAsync($"{message.Author.Username} has registered their user. Type +help for commands. Each command has a --help switch .e.g. +buy --help.");
                }
            }
            return(true);
        }
Ejemplo n.º 26
0
        protected override async Task <bool> ExecuteCommand(IDiscordBot bot, SocketMessage message, StatsOptions option)
        {
            var userId = message.Author.Id.ToString();
            var eb     = new EmbedBuilder {
                Title = $"{message.Author} Stats         ", Color = Color.DarkPurple
            };

            using (var context = _contextFactory.Create())
            {
                var skillSet = await context.SkillSets.Include(t => t.Skills)
                               .FirstOrDefaultAsync(t => t.UserId == userId);

                if (skillSet == null)
                {
                    await message.Channel.SendMessageAsync($"{message.Author} is not registered, please type +register.");

                    return(false);
                }
                var orderedSkills = skillSet.Skills.OrderBy(t => t.SkillId);

                int skillAdded = 0;
                foreach (var skill in orderedSkills)
                {
                    var skillName  = Skill.GetName(skill.SkillId);
                    var emote      = bot.Client.Guilds.SelectMany(x => x.Emotes).FirstOrDefault(x => x.Name.IndexOf(skillName) != -1);
                    var otherField = new EmbedFieldBuilder().WithName(emote.ToString())
                                     .WithValue(skill.MaximumLevel.ToString())
                                     .WithIsInline(true);
                    eb.AddField(otherField);
                    skillAdded++;
                }
            }
            await message.Channel.SendMessageAsync(string.Empty, embed : eb.Build());

            return(true);
        }
Ejemplo n.º 27
0
 public UtilityCommands(IDiscordClient discordClient, IDiscordBot discordBot, IServiceProvider serviceProvider, IBotConfiguration botConfiguration, ICardStackManager cardStackManager)
     : base(discordClient, discordBot, serviceProvider, botConfiguration)
 {
     CardStackManager = cardStackManager;
 }
Ejemplo n.º 28
0
 public UserCommands(IDiscordClient discordClient, IDiscordBot discordBot, IServiceProvider serviceProvider, IBotConfiguration botConfiguration, IUserTrackerService userTracker)
     : base(discordClient, discordBot, serviceProvider, botConfiguration)
 {
     _userTracker = userTracker;
 }
Ejemplo n.º 29
0
 public PushPublisher(IDiscordBot bot)
 {
     this._bot = bot;
 }
Ejemplo n.º 30
0
 public ChatHub(IDiscordBot bot)
 {
     _bot = bot;
 }