private void btnAddNew_Click(object sender, EventArgs e) { //AddNewTab(newTabTitle, this.Font, PublicModule.HomePage); try { string tempclientid = PublicModule.GetNewClientName(); using (Process process = new Process()) { //先添加标签,后面再通过客户发送句柄过来,再设置句柄 AddNewTab("新建标签页", Font, tempclientid, IntPtr.Zero, PublicModule.HomePage); //组合启动参数 string strargs = string.Format("/Client:{0},{1},{2},{3}", PublicModule.channelserver, tempclientid, this.pnlWebBrowser.Handle, PublicModule.HomePage); //创建新的进程 process.StartInfo = new ProcessStartInfo("BrowserX.exe", strargs); process.StartInfo.CreateNoWindow = false; process.StartInfo.UseShellExecute = false; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.StartInfo.RedirectStandardOutput = false; process.Start(); //output = process.StandardOutput.ReadToEnd().ToLower(); } } catch (Exception ex) { throw ex; } }
//输入框文本改变事件 private void chboxAddress_TextChanged(object sender, EventArgs e) { try { _Text = chboxAddress.Text; if (!chboxAddress.Text.Equals("桌面")) { this.DiskSpace = string.Format("剩余:{0}", PublicModule.GetHardDiskSpace(chboxAddress.Text)); } } catch { } }
private void RegisterClientScript() { var sb = new StringBuilder(); var ids = ProductItem.SelectedUsers.Select(i => i.ID).ToArray(); var names = ProductItem.SelectedUsers.Select(i => i.DisplayUserName()).ToArray(); sb.AppendFormat("SelectedUsers_{0} = {1};", ProductItem.ItemName, JavaScriptSerializer.Serialize( new { IDs = ids, Names = names, PeopleImgSrc = PeopleImgSrc, TrashImgSrc = TrashImgSrc, TrashImgTitle = Resources.Resource.DeleteButton, CurrentUserID = SecurityContext.CurrentAccount.ID }) ); ids = ProductItem.SelectedGroups.Select(i => i.ID).ToArray(); names = ProductItem.SelectedGroups.Select(i => i.Name.HtmlEncode()).ToArray(); sb.AppendFormat("SelectedGroups_{0} = {1};", ProductItem.ItemName, JavaScriptSerializer.Serialize( new { IDs = ids, Names = names, GroupImgSrc = GroupImgSrc, TrashImgSrc = TrashImgSrc, TrashImgTitle = Resources.Resource.DeleteButton }) ); if (!ProductItem.CanNotBeDisabled) { sb.AppendFormat("ASC.Settings.AccessRights.initProduct(\"{0}\",\"{1}\",{2});", ProductItem.ID, ProductItem.ItemName, PublicModule.ToString().ToLower() ); } Page.RegisterInlineScript(sb.ToString()); }
private void FormDownloadNew_Load(object sender, EventArgs e) { try { this.cboxSavePath.Visible = true; this.cboxSavePath.AddItem("桌面"); this.cboxSavePath.AddItem("F:\\Download"); this.cboxSavePath.Text = "F:\\Download"; } catch (Exception ex) { } try { if (PublicModule.strDownloadUrl.Length > 0) { Uri tmpUri = new Uri(PublicModule.strDownloadUrl); // 下载文件完整的URL this.chboxAddress.Text = HttpUtility.UrlDecode(PublicModule.strDownloadUrl); // 保存文件夹 this.cboxSavePath.Text = "F:\\Download"; // 解析下载地址中的文件名 if (PublicModule.strDownFileName.Length > 0) { this.tboxFileName.Text = PublicModule.strDownFileName; } else { this.tboxFileName.Text = HttpUtility.UrlDecode(tmpUri.Segments.Last()); } // 组合下载地址,传给下载界面 PublicModule.strDownloadFile = string.Format("{0}://{1}{2}", HttpUtility.UrlDecode(tmpUri.Scheme), HttpUtility.UrlDecode(tmpUri.Host), HttpUtility.UrlDecode(tmpUri.AbsolutePath)); // 测试文件大小 this.tboxFileSize.Text = PublicModule.GetWebFileSize(PublicModule.strDownloadFile); if (this.tboxFileSize.Text.Contains("未知")) { if (PublicModule.strDownFileName.Length > 0) { this.tboxFileSize.Text = string.Format("大小:{0}", PublicModule.GetSize(PublicModule.strDownFileNameSize)); } } } } catch (Exception ex) { } }
// GET: PublicModules public ActionResult Index() { List <ExerciseVideo> exerciseVideoList = db.ExerciseVideos.ToList(); List <PublicModule> publicModuleList = new List <PublicModule>(); ViewBag.ExerciseArea = new SelectList(db.ExerciseTypes, "ExerciseTypeID", "Name"); ViewBag.ExerciseRegion = new SelectList(db.ExerciseRegions, "ExerciseRegionID", "Name"); foreach (ExerciseVideo e in exerciseVideoList) { PublicModule publicmodule = new PublicModule(); Exercise exercise = db.Exercises.Find(e.ExerciseID); ExerciseType exerciseType = db.ExerciseTypes.Find(exercise.ExerciseTypeID); ExerciseRegion exerciseRegion = db.ExerciseRegions.Find(exercise.ExerciseRegionID); publicmodule.VideoURL = e.VideoURL; publicmodule.ExerciseName = exercise.Name; publicmodule.ExerciseRegion = exerciseRegion.Name; publicmodule.ExerciseType = exerciseType.Name; publicModuleList.Add(publicmodule); } return(View(publicModuleList)); }
public void Initialize(TimedTask timer) { DiscordSocketClient blatherDiscord = new DiscordSocketClient(); DiscordSocketClient isabelleDiscord = new DiscordSocketClient(); using (var services = ConfigureServices()) { services.GetRequiredService <IdentityManager>().Initialize(); services.GetRequiredService <CommandHandlingService>().InitializeAsync(isabelleDiscord).Wait(); services.GetRequiredService <Blathers>().InitializeAsync(blatherDiscord).Wait(); services.GetRequiredService <Isabelle>().InitializeAsync(isabelleDiscord).Wait(); PublicModule.Initialize(services); EcoCommands.Initialize(services); var relay = new ChatRelay(services); ActionUtil.AddListener(relay); } Log.WriteLine(Localizer.Do($"Crossing is initialized!")); ChatManager.ServerMessageToAllLoc($"Crossing is initialized! Version 0.1", DefaultChatTags.General); }
public ActionResult retrieveBySelected(int exerciseRegionID, int exerciseTypeID) { ExerciseVideo exerciseVideo = new ExerciseVideo(); List <Exercise> list = db.Exercises.ToList(); PublicModule publicmod = new PublicModule(); foreach (Exercise e in list) { if (e.ExerciseTypeID == exerciseTypeID && e.ExerciseRegionID == exerciseRegionID) { exerciseVideo = db.ExerciseVideos.Where(m => m.ExerciseID == e.ExerciseID).SingleOrDefault(); Exercise exercise = db.Exercises.Find(exerciseVideo.ExerciseID); ExerciseType exerciseType = db.ExerciseTypes.Find(exercise.ExerciseTypeID); ExerciseRegion exerciseRegion = db.ExerciseRegions.Find(exercise.ExerciseRegionID); publicmod.VideoURL = exerciseVideo.VideoURL; publicmod.ExerciseName = exercise.Name; publicmod.ExerciseRegion = exerciseRegion.Name; publicmod.ExerciseType = exerciseType.Name; } } return(Json(publicmod, JsonRequestBehavior.AllowGet)); }
public CommandHandler(IServiceProvider services) { // juice up the fields with these services // since we passed the services in, we can use GetRequiredService to pass them into the fields set earlier _config = services.GetRequiredService <IConfiguration>(); _commands = services.GetRequiredService <CommandService>(); _client = services.GetRequiredService <DiscordSocketClient>(); //_logger = services.GetRequiredService<ILogger>(); _services = services; _pm = new PublicModule(_services); // take action when we execute a command _commands.CommandExecuted += CommandExecutedAsync; // take action when we receive a message (so we can process it, and see if it is a valid command) _client.MessageReceived += MessageReceivedAsync; _client.ReactionAdded += ReactionAddedAsync; _client.ReactionRemoved += ReactionRemovedAsync; //In secrets.json _connStr = _config["ConnStr"]; }
public async Task Start() { Configuration.EnsureExists(); client = new DiscordSocketClient(); client.Log += Log; client.MessageReceived += async(msg) => { var message = msg as SocketUserMessage; var badword = File.ReadAllLines("badwords.txt"); var context = new SocketCommandContext(client, message); SocketTextChannel log = null; int argPos = 0; if (context.Guild != null) { log = context.Guild.GetTextChannel(301094488955420673); } if (doModeration) { if (Array.IndexOf(badword, context.Message.Content.ToLower()) != -1) { await log.SendMessageAsync("<@" + context.User.Id + "> wrote " + context.Message.Content + " in " + context.Channel + "."); switch (rnd.Next(0, 4)) { case 0: await context.Channel.SendMessageAsync("<@" + context.User.Id + "> Don't be rude!"); break; case 1: await context.Channel.SendMessageAsync("<@" + context.User.Id + "> I can't believe you just said that.."); break; case 2: await context.Channel.SendMessageAsync("<@" + context.User.Id + "> Let's not."); break; case 3: await context.Channel.SendMessageAsync("<@" + context.User.Id + "> Start being more polite!"); break; default: break; } await context.Message.DeleteAsync(); return; } var text = Regex.Replace(context.Message.Content, @"[^0-9a-zA-Z]+", " "); //caps prevention if (text == text.ToUpper() && !context.User.IsBot) { switch (rnd.Next(3)) { case 0: await context.Channel.SendMessageAsync("<@" + context.User.Id + "> There's no need to shout."); break; case 1: await context.Channel.SendMessageAsync("<@" + context.User.Id + "> We like it quiet here."); break; case 2: await context.Channel.SendMessageAsync("<@" + context.User.Id + "> SHHHH!"); break; default: break; } await context.Message.DeleteAsync(); return; } } if (PublicModule.askedQuestion && !context.User.IsBot) { if (PublicModule.nmb == 0) { if (Math.Ceiling(Math.Sqrt(PublicModule.sqrt())).ToString() == context.Message.Content) { await context.Channel.SendMessageAsync("<@" + context.User.Id + "> answered correctly"); PublicModule.askedQuestion = false; } } else if (PublicModule.nmb == 1) { if (PublicModule.comb.ToString() == context.Message.Content) { await context.Channel.SendMessageAsync("<@" + context.User.Id + "> answered correctly"); PublicModule.askedQuestion = false; } } else if (PublicModule.nmb == 2) { if (Math.Round(Math.Sin(PublicModule.sin), 2).ToString() == context.Message.Content) { await context.Channel.SendMessageAsync("<@" + context.User.Id + "> answered correctly"); PublicModule.askedQuestion = false; } } else if (PublicModule.nmb == 3) { if (PublicModule.comb.ToString() == context.Message.Content) { await context.Channel.SendMessageAsync("<@" + context.User.Id + "> answered correctly"); PublicModule.askedQuestion = false; } } else if (PublicModule.nmb == 4) { if (PublicModule.comb.ToString() == context.Message.Content) { await context.Channel.SendMessageAsync("<@" + context.User.Id + "> answered correctly"); PublicModule.askedQuestion = false; } } } if (userSuggested.ContainsKey(context.User.Id)) { var currentDM = await context.User.CreateDMChannelAsync(); if (context.Message.Content.ToLower() == "q" && context.Guild == null) { await currentDM.SendMessageAsync("Process cancelled."); userSuggested.Remove(context.User.Id); currentState.Remove(context.User.Id); } else if (context.Guild == null) { switch (currentState[context.User.Id]) { case 1: if (context.Message.Content.ToLower() == "y") { currentState[context.User.Id] = 2; var e = new EmbedBuilder() { Title = "**Title**", Color = new Color(177, 27, 179), Description = "Enter the title for your suggestion (20 characters or less)" }; await currentDM.SendMessageAsync("", false, e); // await currentDM.SendMessageAsync("**Title**\nEnter the title for your suggestion (20 characters or less)"); } break; case 2: if (context.Message.Content.Length > 20) { await currentDM.SendMessageAsync("Please do not exceed the 20 character limit."); } else if (Array.IndexOf(badword, context.Message.Content.ToLower()) != -1) { await currentDM.SendMessageAsync("There's no need to be rude in a suggestion. BE POLITE."); } else { //title = context.Message.Content; titleSug.Add(context.User.Id, context.Message.Content); if (description == "") { currentState[context.User.Id] = 3; var e = new EmbedBuilder() { Title = "**Suggestion**", Color = new Color(177, 27, 179), Description = "Write something that's relevant to the server.\nA good example is: `There should be a role for people who are gamers`\nA bad example is: `Make a role for gamers now, or else..`\nPlease write your suggestion now (500 characters or less)" }; await currentDM.SendMessageAsync("", false, e); } else { currentState[context.User.Id] = 4; EmbedBuilder eb = new EmbedBuilder(); EmbedFooterBuilder efb = new EmbedFooterBuilder(); EmbedAuthorBuilder eab = new EmbedAuthorBuilder(); efb.Text = "Submitted at: " + DateTime.UtcNow; eab.IconUrl = context.User.GetAvatarUrl(); eab.Name = context.User.Username; eb.WithAuthor(eab); eb.Color = new Color(177, 27, 179); eb.WithFooter(efb); eb.AddField((ebf) => { ebf.Name = title; ebf.Value = description; }); await currentDM.SendMessageAsync("**Confirmation**\nThis is what the staff will see:\n", false, eb); await currentDM.SendMessageAsync("\nReady to submit this suggestion?\n[y] Submit\n[r] Start over"); } } break; case 3: if (context.Message.Content.Length > 500) { await currentDM.SendMessageAsync("Please do not exceed the 500 character limit."); } else if (Array.IndexOf(badword, context.Message.Content.ToLower()) != -1) { await currentDM.SendMessageAsync("There's no need to be rude in a suggestion. BE POLITE."); } else { //description = context.Message.Content; descSug.Add(context.User.Id, context.Message.Content); currentState[context.User.Id] = 4; EmbedBuilder eb = new EmbedBuilder(); EmbedFooterBuilder efb = new EmbedFooterBuilder(); EmbedAuthorBuilder eab = new EmbedAuthorBuilder(); efb.Text = "Submitted at: " + DateTime.UtcNow; eab.IconUrl = context.User.GetAvatarUrl(); eab.Name = context.User.Username; eb.WithAuthor(eab); eb.Color = new Color(177, 27, 179); eb.WithFooter(efb); eb.AddField((ebf) => { ebf.Name = titleSug[context.User.Id]; ebf.Value = descSug[context.User.Id]; }); await currentDM.SendMessageAsync("**Confirmation**\nThis is what the staff will see:\n", false, eb); await currentDM.SendMessageAsync("\nReady to submit this suggestion?\n[y] Submit\n[r] Start over"); } break; case 4: if (context.Message.Content.ToLower() == "y" && context.Guild == null) { EmbedBuilder eb = new EmbedBuilder(); EmbedFooterBuilder efb = new EmbedFooterBuilder(); EmbedAuthorBuilder eab = new EmbedAuthorBuilder(); efb.Text = "Submitted at: " + DateTime.UtcNow; eab.IconUrl = context.User.GetAvatarUrl(); eab.Name = context.User.Username; eb.WithAuthor(eab); eb.Color = new Color(177, 27, 179); eb.WithFooter(efb); eb.AddField((ebf) => { ebf.Name = titleSug[context.User.Id]; ebf.Value = descSug[context.User.Id]; }); await channel.SendMessageAsync("", false, eb.Build()); await currentDM.SendMessageAsync("Thanks for your suggestion! c:"); description = ""; title = ""; userSuggested.Remove(context.User.Id); titleSug.Remove(context.User.Id); descSug.Remove(context.User.Id); currentState.Remove(context.User.Id); } else if (context.Message.Content.ToLower() == "r" && context.Guild == null) { currentState[context.User.Id] = 1; description = ""; title = ""; titleSug.Remove(context.User.Id); descSug.Remove(context.User.Id); var e = new EmbedBuilder() { Title = "**Make a suggestion**\n", Color = new Color(177, 27, 179), Description = "Please be aware of the following:\n" + "- Your Discord Username will be recorded.\n" + "- Your suggestion will be visible for anyone to see.\n" + "- Please do NOT misuse this command. Appropriate action will be taken by staff should you ignore this.\n\n" + "Is this OK?\nRespond with `y` if you understood the above or press `q` if you don't." }; await currentDM.SendMessageAsync("", false, e); /* await currentDM.SendMessageAsync("**Make a suggestion**\n" + * "Please be aware of the following:\n" + * "- Your Discord Username will be recorded.\n" + * "- Your suggestion will be visible for anyone to see.\n" + * "- Please do NOT misuse this command. Appropriate action will be taken by staff should you ignore this.\n\n" + * "Is this OK?\nRespond with `y` if you understood the above or press `q` if you don't."); */ } else { await currentDM.SendMessageAsync("Respond with `y` or `q`."); } break; } } } if (message.HasMentionPrefix(client.CurrentUser, ref argPos) && message.Content.Contains("<3")) { await context.Channel.SendMessageAsync("<@" + context.User.Id + "> WHAT?!!! I want hearts! <3"); } else if (message.HasMentionPrefix(client.CurrentUser, ref argPos) && message.Content.Contains("?")) { await context.Channel.SendMessageAsync("<@" + context.User.Id + "> Maybe? I don't know."); } else if (message.HasMentionPrefix(client.CurrentUser, ref argPos) && message.Content.Contains("hello") || message.HasMentionPrefix(client.CurrentUser, ref argPos) && message.Content.Contains("hi")) { await context.Channel.SendMessageAsync("<@" + context.User.Id + "> Hey there!"); } else if (message.HasMentionPrefix(client.CurrentUser, ref argPos) && message.Content.Contains("jason")) { await context.Channel.SendMessageAsync("<@" + context.User.Id + "> Jason? What about him? He programmed me."); } else if (message.HasMentionPrefix(client.CurrentUser, ref argPos) && message.Content.Contains("astralmod") && message.Content.Contains("hate")) { await context.Channel.SendMessageAsync("<@" + context.User.Id + "> AstralMod? I don't like him."); } else if (message.HasMentionPrefix(client.CurrentUser, ref argPos) && message.Content.Contains("f**k you") || message.HasMentionPrefix(client.CurrentUser, ref argPos) && message.Content.Contains("f**k off")) { await context.Channel.SendMessageAsync("<@" + context.User.Id + "> Wanna get banned?"); } else if (message.HasMentionPrefix(client.CurrentUser, ref argPos) && message.Content.Contains("yes") || message.HasMentionPrefix(client.CurrentUser, ref argPos) && message.Content.Contains("yeah") || message.HasMentionPrefix(client.CurrentUser, ref argPos) && message.Content.Contains("right?")) { await context.Channel.SendMessageAsync("<@" + context.User.Id + "> I guess."); } else if (message.HasMentionPrefix(client.CurrentUser, ref argPos) && message.Content.Contains("no") || message.HasMentionPrefix(client.CurrentUser, ref argPos) && message.Content.Contains("nope") || message.HasMentionPrefix(client.CurrentUser, ref argPos) && message.Content.Contains("nah")) { await context.Channel.SendMessageAsync("<@" + context.User.Id + "> I guess not."); } }; client.MessageDeleted += async(e, msg) => { var message = msg as SocketUserMessage; var context = new SocketCommandContext(client, message); if (!context.User.IsBot) { await context.Guild.GetTextChannel(301094488955420673).SendMessageAsync($"[{context.Guild}] {context.Message.Timestamp}: {context.User} {"deleted message in <#" + context.Channel.Id + ">"}: {"```" + context.Message.Content + "```"}"); } }; client.MessageUpdated += async(e, msg, s) => { var message = msg as SocketUserMessage; var context = new SocketCommandContext(client, message); if (!context.User.IsBot) { //await context.Guild.GetTextChannel(301094488955420673).SendMessageAsync($"[{context.Guild}] {startTime}: {context.User} {"changed message in <#" + context.Channel.Id + ">"}: {"```" + message. + "```"} {"```" + e.Value + "```"}"); } }; var timer = new System.Threading.Timer(e => currentGame(), null, TimeSpan.Zero, TimeSpan.FromMinutes(10)); await client.LoginAsync(TokenType.Bot, Configuration.Load().Token); await client.StartAsync(); var map = new DependencyMap(); map.Add(client); handler = new CommandHandler(); await handler.Install(map); await Task.Delay(-1); }