コード例 #1
0
        public async Task UnlinkServices(CommandContext ctx)
        {
            var msg = await ctx.RespondAsync(embed : EmbedTemplates.CreateInfoEmbed("Unlink Services",
                                                                                    "Unlinking all services. Please wait..."));

            DiscordService.ResetAllServices(ctx);
            await msg.ModifyAsync(
                embed : new Optional <DiscordEmbed>(
                    EmbedTemplates.CreateSuccessEmbed(description: "Unlinked all services.")));
        }
コード例 #2
0
ファイル: LobbyLogic.cs プロジェクト: edmundmunday/OpenRA
        void OnGameStart()
        {
            Ui.CloseWindow();

            var state = skirmishMode ? DiscordState.PlayingSkirmish : DiscordState.PlayingMultiplayer;

            DiscordService.UpdateStatus(state);

            onStart();
        }
コード例 #3
0
        public Worker(ILogger <Worker> logger, IConfiguration configuration, ILogger <Bot> botLogger, DiscordService discordService)
        {
            Logger         = logger;
            Configuration  = configuration;
            DiscordService = discordService;

            Instance = this;

            bot = new Bot(configuration, botLogger, discordService);
        }
コード例 #4
0
ファイル: ApiSandboxController.cs プロジェクト: zio3/VetCoin
 public ApiSandboxController(SuperChatService superChatService, DiscordService discordService, ApplicationDbContext applicationDbContext, SiteContext siteContext, CoreService coreService, IconCheckService iconCheckService, StaticSettings staticSettings)
 {
     SuperChatService = superChatService;
     DiscordService   = discordService;
     DbContext        = applicationDbContext;
     SiteContext      = siteContext;
     CoreService      = coreService;
     IconCheckService = iconCheckService;
     StaticSettings   = staticSettings;
 }
コード例 #5
0
        /// <summary>
        /// Synchronizes the channels in the <paramref name="context"/> with the
        /// channels from the <paramref name="discordService"/>
        /// </summary>
        /// <param name="context">The database context</param>
        /// <param name="discordService">The discord service</param>
        public static void SyncChannels(
            DatabaseContext context
            , DiscordService discordService)
        {
            IEnumerable <SocketTextChannel> textChannels
                = discordService.GetTextChannels();

            EnableChannels(context, textChannels);
            DisableDroppedChannels(context, textChannels);
        }
コード例 #6
0
        public GuildWelcomeMessageService(IOptions <AppSettings> options,
                                          DiscordService discord,
                                          DiscordErrorReporter errorReporter)
        {
            _settings      = options.Value;
            _discord       = discord;
            _errorReporter = errorReporter;

            _discord.JoinedGuild += HandleJoinedGuild;
        }
コード例 #7
0
        /// <summary>
        /// Lists trackers for the guild in which the command was sent in
        /// </summary>
        /// <param name="message">The request message</param>
        /// <param name="discordService">The discord service</param>
        /// <param name="context">The database context</param>
        private static async Task ListTrackersAsync(
            SocketMessage message
            , DiscordService discordService
            , DatabaseContext context
            )
        {
            Channel?channel = context.GetChannel(message.Channel.Id);

            if (channel == null)
            {
                return;
            }

            IEnumerable <Tracker> trackers = context.GetActiveTrackers(channel.Guild);

            if (!trackers.Any())
            {
                await discordService
                .ReplyAsync(message, "No active trackers found!")
                .ConfigureAwait(false);

                return;
            }

            int gameAbbreviationLength = Math
                                         .Max(trackers
                                              .OrderByDescending(t => t.Game.Abbreviation.Length)
                                              .Select(t => t.Game)
                                              .First()
                                              .Abbreviation.Length + 2
                                              , "Abbreviation".Length + 2);

            int gameNameLength = trackers
                                 .OrderByDescending(t => t.Game.Name.Length)
                                 .Select(t => t.Game)
                                 .First()
                                 .Name
                                 .Length + 2;

            string reply = "```\r\n";

            reply += "Abbreviation".PadRight(gameAbbreviationLength);
            reply += "Game".PadRight(gameNameLength);
            reply += "Channel\r\n";

            foreach (Tracker tracker in trackers)
            {
                string entry = $"{tracker.Game.Abbreviation.PadRight(gameAbbreviationLength)}{tracker.Game.Name.PadRight(gameNameLength)}#{tracker.Channel.DisplayName}";
                reply += $"{entry}\r\n";
            }

            reply += "```";

            await discordService.ReplyAsync(message, reply).ConfigureAwait(false);
        }
コード例 #8
0
 /// <summary>
 /// Initializes the discord service
 /// </summary>
 private static void InitDiscordService()
 {
     _discordService = new DiscordService();
     _discordService.OnDisconnected     += OnDiscordDisconnected;
     _discordService.OnReady            += OnDiscordReady;
     _discordService.OnChannelCreated   += OnDiscordChannelCreated;
     _discordService.OnChannelDestroyed += OnDiscordChannelDeleted;
     _discordService.OnGuildJoined      += OnDiscordGuildJoined;
     _discordService.OnGuildLeft        += OnDiscordGuildLeft;
     _discordService.OnCommandReceived  += OnDiscordCommandReceived;
 }
コード例 #9
0
ファイル: LobbyLogic.cs プロジェクト: shakhmetov/OpenRA
        void OnGameStart()
        {
            Ui.CloseWindow();

            var state   = skirmishMode ? DiscordState.PlayingSkirmish : DiscordState.PlayingMultiplayer;
            var details = map.Title + " - " + orderManager.LobbyInfo.GlobalSettings.ServerName;

            DiscordService.UpdateStatus(state, details);

            onStart();
        }
コード例 #10
0
ファイル: ReplayBrowserLogic.cs プロジェクト: zhao212/OpenRA
        void WatchReplay()
        {
            if (selectedReplay != null && ReplayUtils.PromptConfirmReplayCompatibility(selectedReplay))
            {
                cancelLoadingReplays = true;

                DiscordService.UpdateStatus(DiscordState.WatchingReplay);

                Game.JoinReplay(selectedReplay.FilePath);
            }
        }
コード例 #11
0
 public ScheduledExecutionHostedService(IServiceProvider services,
                                        //   IOptions<AppSettings> options,
                                        DiscordService discordService,
                                        ILogger <ScheduledExecutionHostedService <T> > logger
                                        )
 {
     Services       = services;
     DiscordService = discordService;
     Logger         = logger;
     //   AppSettings = options.Value;
 }
コード例 #12
0
        public async Task InviteTests_ValidateDiscorcdInviteExpired_ReturnsFalse()
        {
            //Arrange
            DiscordService _workspaceService = new DiscordService();
            string         inviteLink        = "https://discordapp.com/invite/BFydMyn";
            //Act
            var result = await _workspaceService.GetInviteStatus(inviteLink);

            //Assert
            Assert.False(result.Valid);
        }
コード例 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SetCommands"/> class.
 /// </summary>
 /// <param name="discordService">The Discord integration service.</param>
 /// <param name="characterService">The character service.</param>
 /// <param name="characterRoles">The character role service.</param>
 public SetCommands
 (
     DiscordService discordService,
     CharacterDiscordService characterService,
     CharacterRoleService characterRoles
 )
 {
     _discord        = discordService;
     _characters     = characterService;
     _characterRoles = characterRoles;
 }
コード例 #14
0
        public async Task InviteTests_ValidateDiscorcdInviteNotExpired_ReturnsTrue()
        {
            //Arrange
            DiscordService _workspaceService = new DiscordService();
            string         inviteLink        = "https://discord.gg/GmurfHD";
            //Act
            var result = await _workspaceService.GetInviteStatus(inviteLink);

            //Assert
            Assert.True(result.Valid);
        }
コード例 #15
0
 public BaseCommands(IStatisticsManager statisticsManager, IYouTubeManager youtubeManager,
                     IApiAiManager apiAiManager, DiscordService discordService, DiscordShardedClient discord,
                     IOptions <BotSettings> botSettings, FileService fileService) : base(botSettings)
 {
     _statisticsManager = statisticsManager;
     _youtubeManager    = youtubeManager;
     _apiAiManager      = apiAiManager;
     _discordService    = discordService;
     _discord           = discord;
     _botSettings       = botSettings.Value;
     _fileService       = fileService;
 }
コード例 #16
0
 public View(DiscordService discord,
             MessageHandlerService messageHandler,
             ReactionHandlerService reactionHandler,
             InteractiveManager interactive,
             FeedChannelUpdateService feedChannelUpdater)
 {
     _discord            = discord;
     _messageHandler     = messageHandler;
     _reactionHandler    = reactionHandler;
     _interactive        = interactive;
     _feedChannelUpdater = feedChannelUpdater;
 }
コード例 #17
0
 public DiscordErrorReporter(IOptions <AppSettings> options,
                             IHostingEnvironment environment,
                             DiscordService discord,
                             InteractiveManager interactiveManager,
                             ILogger <DiscordErrorReporter> logger)
 {
     _settings           = options.Value;
     _environment        = environment;
     _discord            = discord;
     _interactiveManager = interactiveManager;
     _logger             = logger;
 }
コード例 #18
0
        /// <summary>
        /// Triggers every time a game is won.
        /// </summary>
        /// <param name="winner"></param>
        /// <param name="gameID"></param>
        public void ProcessWinner(string winner, int gameID)
        {
            // Wait until someone has won two games, then report the results to Discord.
            match.Winners.GetRecordData(out var first, out var record);
            if (first.Wins == 2)
            {
                var loser = match.Players.FirstOrDefault(d => d != winner);
#pragma warning disable CS4014 // We don't actually want to block on the message.
                DiscordService.SendToArbiraryChannelAsync($":trophy: {winner} {record} {loser}", 291179039291473920);
#pragma warning restore CS4014
            }
        }
コード例 #19
0
 public ScheduledExecutionService(
     DiscordService discordService,
     CoreService coreService,
     IconCheckService iconCheckService,
     StaticSettings staticSettings
     )
 {
     DiscordService   = discordService;
     CoreService      = coreService;
     IconCheckService = iconCheckService;
     StaticSettings   = staticSettings;
 }
コード例 #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SetCommands"/> class.
 /// </summary>
 /// <param name="discordService">The Discord integration service.</param>
 /// <param name="feedbackService">The feedback service.</param>
 /// <param name="characterService">The character service.</param>
 /// <param name="characterRoles">The character role service.</param>
 public SetCommands
 (
     DiscordService discordService,
     UserFeedbackService feedbackService,
     CharacterDiscordService characterService,
     CharacterRoleService characterRoles
 )
 {
     _discord        = discordService;
     _feedback       = feedbackService;
     _characters     = characterService;
     _characterRoles = characterRoles;
 }
コード例 #21
0
        void mss_SampleRequested(MediaStreamSource sender, MediaStreamSourceSampleRequestedEventArgs args)
        {
            DiscordService discordService = (DiscordService)App.Current.Services.GetRequiredService <IDiscordService>();

            foreach ((string key, WebrtcManager manager) in discordService.Streams)
            {
                if (key.EndsWith(UserId.ToString()))
                {
                    manager.GenerateSample(args.Request);
                    return;
                }
            }
        }
コード例 #22
0
        public async Task ForceLinkService(CommandContext ctx, int serviceId)
        {
            await ctx.Message.DeleteAsync();

            if (DiscordService.LinkService(ctx.Guild.Id, serviceId))
            {
                await ctx.RespondAsync(embed : EmbedTemplates.CreateSuccessEmbed(description: "**Linked Service**"));
            }
            else
            {
                await ctx.RespondAsync(
                    embed : EmbedTemplates.CreateErrorEmbed(description: "**Failed to link service**"));
            }
        }
コード例 #23
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            var discordService = new DiscordService("NzI5MjU5NzU1ODYzODAxOTQ2.XwGcnQ.6goBosxHNX7o02qThz-AcJPX32g");

            await discordService.Start();

            while (!stoppingToken.IsCancellationRequested)
            {
                _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
                await Task.Delay(1000, stoppingToken);
            }

            await discordService.Stop();
        }
コード例 #24
0
ファイル: LobbyLogic.cs プロジェクト: edmundmunday/OpenRA
        void UpdateDiscordStatus()
        {
            var mapTitle        = map.Title;
            var numberOfPlayers = 0;
            var slots           = 0;

            if (!skirmishMode)
            {
                foreach (var kv in orderManager.LobbyInfo.Slots)
                {
                    if (kv.Value.Closed)
                    {
                        continue;
                    }

                    slots++;
                    var client = orderManager.LobbyInfo.ClientInSlot(kv.Key);

                    if (client != null)
                    {
                        numberOfPlayers++;
                    }
                }
            }

            if (updateDiscordStatus)
            {
                string secret = null;
                if (orderManager.LobbyInfo.GlobalSettings.Dedicated)
                {
                    var endpoint = orderManager.Endpoint.GetConnectEndPoints().First();
                    secret = string.Concat(endpoint.Address, "|", endpoint.Port);
                }

                var state = skirmishMode ? DiscordState.InSkirmishLobby : DiscordState.InMultiplayerLobby;
                DiscordService.UpdateStatus(state, mapTitle, secret, numberOfPlayers, slots);

                updateDiscordStatus = false;
            }
            else
            {
                if (!skirmishMode)
                {
                    DiscordService.UpdatePlayers(numberOfPlayers, slots);
                }

                DiscordService.UpdateDetails(mapTitle);
            }
        }
コード例 #25
0
        public void InitPlugin(TabPage pluginScreenSpace, Label pluginStatusText)
        {
            Settings = new PluginSettings(this);

            DiscordService = new DiscordService();

            ACTTabControl          = new ACTTabControl(this);
            pluginScreenSpace.Text = "Kikisen Talk";
            pluginScreenSpace.Controls.Add(ACTTabControl);

            Settings.Load();
            ClearParamMessages();
            ClearBatchMessage();
            ActGlobals.oFormActMain.OnLogLineRead += OnLogLineRead;
        }
コード例 #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CharacterCommands"/> class.
 /// </summary>
 /// <param name="database">A database context from the context pool.</param>
 /// <param name="contentService">The content service.</param>
 /// <param name="discordService">The Discord integration service.</param>
 /// <param name="feedbackService">The feedback service.</param>
 /// <param name="characterService">The character service.</param>
 public CharacterCommands
 (
     GlobalInfoContext database,
     ContentService contentService,
     DiscordService discordService,
     UserFeedbackService feedbackService,
     CharacterService characterService
 )
 {
     this.Database   = database;
     this.Content    = contentService;
     this.Discord    = discordService;
     this.Feedback   = feedbackService;
     this.Characters = characterService;
 }
コード例 #27
0
        public async Task PlayersTask(CommandContext ctx)
        {
            var settings =
                new NexusModuleConfiguration <PlayersMenuSettings>("PlayerMenuSettings", "./Config/TCAdminModule/")
                .GetConfiguration();
            await ctx.TriggerTypingAsync();

            var service = await DiscordService.GetService(ctx);

            var server = new Server(service.ServerId);

            var query = ServerQuery.GetQueryResults(server, new TCAdmin.GameHosting.SDK.Objects.Game(service.GameId),
                                                    service);

            if (query.NumPlayers == 0)
            {
                await ctx.RespondAsync(
                    embed : EmbedTemplates.CreateErrorEmbed(service.NameNoHtml, "**No players online**"));

                return;
            }

            if (query.NumPlayers != query.Players.Count)
            {
                await ctx.RespondAsync(embed : EmbedTemplates.CreateInfoEmbed(service.NameNoHtml,
                                                                              $"There are **{query.NumPlayers}/{query.MaxPlayers}** online!"));

                return;
            }

            var embed = new DiscordEmbedBuilder
            {
                Title     = $"{service.Name} | Players: {query.NumPlayers}/{query.MaxPlayers}",
                Color     = new Optional <DiscordColor>(new DiscordColor(settings.HexColor)),
                Timestamp = DateTime.Now,
                Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail
                {
                    Url = settings.ThumbnailUrl
                }
            };

            foreach (var player in query.Players.OrderBy(x => x.Name))
            {
                embed.Description += $":bust_in_silhouette: {player.Name}\n";
            }

            await ctx.RespondAsync(embed : embed);
        }
コード例 #28
0
        public ReactionHandlerService(DiscordService discord,
                                      GuildSettingsCache guildSettingsCache,
                                      DiscordErrorReporter errorReporter,
                                      ILogger <ReactionHandlerService> logger,
                                      InteractiveManager interactiveManager)
        {
            _discord            = discord;
            _guildSettingsCache = guildSettingsCache;
            _errorReporter      = errorReporter;
            _logger             = logger;

            _reactionHandlers = new IReactionHandler[]
            {
                interactiveManager
            };
        }
コード例 #29
0
        public GuildSettingsSyncService(IServiceProvider services,
                                        GuildSettingsCache cache,
                                        DiscordService discord)
        {
            _services = services;
            _cache    = cache;
            _discord  = discord;

            _discord.GuildAvailable += RefreshGuildAsync;
            _discord.JoinedGuild    += RefreshGuildAsync;

            foreach (var guild in discord.Guilds)
            {
                cache.RefreshQueue.Enqueue(guild.Id);
            }
        }
コード例 #30
0
ファイル: Details.cshtml.cs プロジェクト: zio3/VetCoin
        private async Task Notification(UserContext userContext, Donation donation, Doner doner)
        {
            var fields = new List <DiscordService.DiscordEmbed.Field>();

            fields.Add(new DiscordService.DiscordEmbed.Field
            {
                name   = "金額",
                value  = $"{doner.Amount}{StaticSettings.CurrenryUnit}",
                inline = false
            });

            if (!string.IsNullOrWhiteSpace(doner.Comment))
            {
                fields.Add(new DiscordService.DiscordEmbed.Field
                {
                    name   = "メッセージ",
                    value  = doner.Comment,
                    inline = false
                });
            }

            var total = DbContext.Doners.AsQueryable().Where(c => c.DonationId == donation.Id)
                        .Where(c => c.DonerState != DonerState.Cancel)
                        .Where(c => c.VetMemberId != donation.VetMemberId)
                        .Sum(c => c.Amount);

            fields.Add(new DiscordService.DiscordEmbed.Field
            {
                name   = "支援総額",
                value  = $"{total}{StaticSettings.CurrenryUnit}",
                inline = false
            });


            await DiscordService.SendMessage(DiscordService.Channel.CrowdFundingNotification, string.Empty, new DiscordService.DiscordEmbed
            {
                title  = donation.Title,
                url    = $"{StaticSettings.SiteBaseUrl}Donations/Details?id={donation.Id}",
                author = new DiscordService.DiscordEmbed.Author
                {
                    url      = userContext.CurrentUser.GetMemberPageUrl(StaticSettings.SiteBaseUrl),
                    icon_url = userContext.CurrentUser.GetAvaterIconUrl(),
                    name     = userContext.CurrentUser.Name
                },
                fields = fields.ToArray()
            });
        }