Example #1
0
        public async Task OnUserJoinServer(SocketGuildUser user)
        {
            var message = $"Hi {user.Mention}!  Welcome to **{user.Guild.Name}**.\n\n";

            if (_verificationService.IsUserVerified(user.Id))
            {
                var verifiedRole = _discord.GetGuild(_guildId).GetRole(_verifiedRoleId);
                message +=
                    "You have already verified your discord account and linked it to your forum profile! You have been set a Verified role, woohoo! :partying_face:";

                user.AddRoleAsync(verifiedRole);
                Logger.Write($"[OnUserJoinServer] {user.Id} has joined the server, verified role set");
            }
            else
            {
                message += "You can link your forum account to your discord profile and get a Verified role.  Type `/verify` below to start the process!";
            }

            try
            {
                var dm = await user.GetOrCreateDMChannelAsync();

                dm.SendMessageAsync(message);
            }
            catch (Exception e)
            {
                Logger.Write($"[OnUserJoinServer] {user.Id} failed to send welcome msg: {e.Message}");
            }

            _cacheService.ClearCache(user.Id);
        }
Example #2
0
        // Code to execute when the application is launching (eg, from Start)
        // This code will not execute when the application is reactivated
        private async void Application_Launching(object sender, LaunchingEventArgs e)
        {
            //Clear cache data
            var cacheService = new CacheService();

            cacheService.ClearCache();

            //Clear image data
            var cacheSetting = new IsolatedStorageProperty <bool>("ClearImageCache");

            if (cacheSetting.Value)
            {
                StorageHelper.ClearImageCache();
                cacheSetting.Value = false;
            }

            try
            {
                await VoiceCommandService.InstallCommandSetsFromFileAsync(new Uri("ms-appx:///CortanaCommands.xml", UriKind.Absolute));
            }
            catch (Exception ex)
            {
                BugSenseHandler.Instance.LogException(ex);
            }
        }
Example #3
0
 public SettingsViewModel()
 {
     // 由于默认值不是常量,因此需要动态注册
     SettingService.Instance.RegisterSetting(this, nameof(PriorSource), null, MediaSources.First());
     SettingService.Instance.RegisterSetting(this, nameof(Theme), null, ThemeList.First());
     SettingService.Instance.RegisterSetting(this, nameof(ReminderSpanAhead), null, TimeSpan.FromMinutes(5));
     SettingService.Instance.ApplySettingAttributes(this);
     ClearCacheFiles = new DelegateCommand(async() =>
     {
         await CacheService.ClearCache();
         await new MessageDialog("成功清空缓存", "成功").ShowAsync();
         CacheFileSize = 0;
     }, () => CacheFileSize > 0);
 }
        public async Task Verify(string option = "")
        {
            var user = Context.User;

            if (_verificationService.IsUserVerified(user.Id))
            {
                Context.Message.DeleteAsync();
                user.SendMessageAsync("Your discord account is already verified!");
                return;
            }

            if (Context.Guild != null)
            {
                Context.Message.DeleteAsync();
                user.SendMessageAsync(StringConstants.GetVerificationCmdDescription(user.Mention));
                return;
            }

            var guildUser = Context.Client.GetGuild(_guildId).GetUser(user.Id);

            if (guildUser == null)
            {
                ReplyAsync($"I couldn't find you on {Context.Client.GetGuild(_guildId).Name}. If you are on the server, try changing your status, if not, join and then try your luck verifying!");
                return;
            }

            var userVerificationState = _cacheService.GetUserVerificationState(user.Id);

            switch (option.ToLower().Trim())
            {
            case "done":
                if (userVerificationState == VerificationStates.None)
                {
                    ReplyAsync("Your verification state is not known, type `/verify` to start your verification process.");
                    return;
                }

                int    cachedProfile = _cacheService.GetUserForumId(user.Id);
                string cachedToken   = _cacheService.GetUserToken(user.Id);
                if (cachedProfile == -1 ||
                    cachedToken == "" ||
                    userVerificationState != VerificationStates.WaitingConfirm)
                {
                    _cacheService.ClearCache(user.Id);
                    ReplyAsync("Your verification process hasn't been initiated, type `/verify` to start your verification process.");
                    return;
                }

                string forumName = _verificationService.GetForumProfileNameIfContainsToken(cachedProfile, cachedToken);
                if (forumName == string.Empty)
                {
                    _userService.SetUserCooldown(user.Id, 15);
                    ReplyAsync("I couldn't find the token in your profile. Make sure your profile is set to public and the token is in your biography section." +
                               "\n" +
                               ":no_entry: You are allowed to check again in 15 seconds.");
                    return;
                }

                // if for some reason something is f****d and the forum id is found as linked, deny process and clear everything
                if (_verificationService.IsForumProfileLinked(cachedProfile))
                {
                    _cacheService.ClearCache(user.Id);
                    ReplyAsync("Sorry! This profile is already found to be linked with a discord account!");
                    return;
                }

                _cacheService.ClearCache(user.Id);
                _verificationService.StoreUserVerification(
                    user.Id,
                    cachedProfile,
                    forumName,
                    user.Username);

                var discordServer = Context.Client.GetGuild(_guildId);
                discordServer
                .GetTextChannel(_adminChannelId)
                .SendMessageAsync($"{guildUser.Mention} ({guildUser.Username}) has successfully verified to **{forumName}** <{_forumProfileUrl}{cachedProfile}>");

                ReplyAsync(StringConstants.GetVerificationSuccessMessage(user.Mention, cachedProfile));

                guildUser.AddRoleAsync(discordServer.GetRole(_verifiedRoleId));
                break;

            case "cancel":
                if (userVerificationState == VerificationStates.None)
                {
                    ReplyAsync("Nothing to cancel!");
                    return;
                }

                _cacheService.ClearCache(user.Id);
                ReplyAsync("Session successfully cleared. You can start the verification process again by typing `/verify <profile id>`");
                break;

            default:
                if (userVerificationState != VerificationStates.None)
                {
                    ReplyAsync("Your verification is awaiting you to place the token in your profile biography. `/verify done` once done or `/verify cancel` to cancel the process.");
                    return;
                }

                if (option == string.Empty)
                {
                    ReplyAsync(StringConstants.GetVerificationCmdDescription(user.Mention));
                    return;
                }

                int profile_id = -1;
                if (!Int32.TryParse(option, out profile_id))
                {
                    ReplyAsync(StringConstants.GetVerificationCmdDescription(user.Mention));
                    return;
                }

                if (profile_id < 1)
                {
                    ReplyAsync("Sorry! This doesn't look like a valid profile id to me.");
                    return;
                }

                if (_verificationService.IsForumProfileLinked(profile_id))
                {
                    _cacheService.ClearCache(user.Id);
                    await ReplyAsync("This profile is already linked to a discord account!");

                    return;
                }

                string token = StringHelper.GenerateRandom(10);

                _cacheService.SetUserVerificationState(user.Id, VerificationStates.WaitingConfirm);
                _cacheService.SetUserToken(user.Id, token);
                _cacheService.SetUserForumId(user.Id, profile_id);

                ReplyAsync(StringConstants.GetVerificationWaitingMessage(user.Mention, profile_id, token));
                break;
            }
        }