/// <summary> /// 编辑框 头像 文本有变动 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void textBox_touXiang_TextChanged(object sender, EventArgs e) { string touXiang = Tieba.GuoLvTouXiangID(textBox_touXiang.Text); if (string.IsNullOrEmpty(touXiang)) { return; } TiebaMingPianJieGou mingPianJieGou = TiebaWeb.GetTiebaMingPian(touXiang); if (!mingPianJieGou.HuoQuChengGong) { return; } pictureBox1.ImageLocation = $"http://tb.himg.baidu.com/sys/portrait/item/{touXiang}"; textBox_zhuXianZhangHao.Text = Tools.HuoQuZhuXianZhangHao(mingPianJieGou); }
/// <summary> /// 批量添加 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { if (Tools.HuoQuFengJinShiChang(dateTimePicker1, dateTimePicker2) <= 0) { MessageBox.Show("封禁时长必须大于0", "笨蛋雪说:", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Exclamation); return; } button1.Enabled = false; textBox1.Enabled = false; dateTimePicker1.Enabled = false; dateTimePicker2.Enabled = false; button_day_type1.Enabled = false; button_day_type2.Enabled = false; button_day_type3.Enabled = false; Task.Run(() => { progressBar1.Minimum = 0; progressBar1.Maximum = 200; progressBar1.Value = 0; int chengGongShu = 0, shiBaiShu = 0, chongFuShu = 0; string kaiShiShiJian = dateTimePicker1.Text; string jieShuShiJian = dateTimePicker2.Text; string[] yongHuMingDan = textBox1.Text.Split(Environment.NewLine.ToCharArray()); string shiBaiMingDan = string.Empty; //过滤+去重复 PiLiangTianJiaHuanCun.LieBiao = new List <PiLiangTianJiaHuanCun.JieGou>(); for (int i = 0; i < yongHuMingDan.Length; i++) { progressBar1.Value = (i + 1) * 100 / yongHuMingDan.Length; if (string.IsNullOrEmpty(yongHuMingDan[i])) { continue; } string[] fenGe = yongHuMingDan[i].Split('|'); if (fenGe.Length != 2) { continue; } string tiebaName = fenGe[0]; //分类 string touXiangID = "", zhuXianZhangHao = ""; //贴吧数字ID if (Regex.IsMatch(fenGe[1], "^[0-9]{1,}$")) { TiebaYongHuSouSuoJieGou tiebaYongHuSouSuoJieGou = TiebaApp.TiebaYongHuSouSuo(Convert.ToInt64(fenGe[1])); if (tiebaYongHuSouSuoJieGou.HuoQuChengGong) { touXiangID = tiebaYongHuSouSuoJieGou.TouXiangID; zhuXianZhangHao = Tools.HuoQuZhuXianZhangHao(tiebaYongHuSouSuoJieGou); } } //用户名或头像 else { TiebaMingPianJieGou mingPianJieGou = TiebaWeb.GetTiebaMingPian(fenGe[1]); if (mingPianJieGou.HuoQuChengGong) { touXiangID = mingPianJieGou.TouXiang; zhuXianZhangHao = Tools.HuoQuZhuXianZhangHao(mingPianJieGou); } } //跳过获取失败的 if (string.IsNullOrEmpty(touXiangID)) { shiBaiMingDan += $"{yongHuMingDan[i]}\r\n"; shiBaiShu++; continue; } //去重复 if (PiLiangTianJiaHuanCun.LieBiao.Count(md => md.TiebaName == fenGe[0] && md.TouXiangID == fenGe[1]) > 0) { chongFuShu++; continue; } PiLiangTianJiaHuanCun.LieBiao.Add(new PiLiangTianJiaHuanCun.JieGou { TiebaName = tiebaName, TouXiangID = touXiangID, ZhuXianZhangHao = zhuXianZhangHao }); } progressBar1.Value = 100; //添加到数据库 for (int i = 0; i < PiLiangTianJiaHuanCun.LieBiao.Count; i++) { progressBar1.Value = ((i + 1) * 100 / PiLiangTianJiaHuanCun.LieBiao.Count) + 100; string tiebaName = PiLiangTianJiaHuanCun.LieBiao[i].TiebaName; string touXiang = PiLiangTianJiaHuanCun.LieBiao[i].TouXiangID; string yongHuMing = PiLiangTianJiaHuanCun.LieBiao[i].ZhuXianZhangHao; TiebaMingPianJieGou mingPianJieGou = TiebaWeb.GetTiebaMingPian(touXiang); if (!mingPianJieGou.HuoQuChengGong) { shiBaiMingDan += $"{tiebaName}|{(string.IsNullOrEmpty(yongHuMing) ? touXiang : yongHuMing)}\r\n"; shiBaiShu++; continue; } //数据库检查重复 if (Form1.access.GetDataTable($"select * from 封禁列表 where 头像='{mingPianJieGou.TouXiang}' and 贴吧名='{tiebaName}'").Rows.Count > 0) { chongFuShu++; continue; } int jieGuo = Form1.access.DoCommand($"insert into 封禁列表 (用户名,头像,贴吧名,最后封禁时间,循环开始时间,循环结束时间)" + $" values('{Tools.HuoQuZhuXianZhangHao(mingPianJieGou)}','{mingPianJieGou.TouXiang}','{tiebaName}','1970-01-01','{kaiShiShiJian}','{jieShuShiJian}')"); if (jieGuo > 0) { chengGongShu++; } else { shiBaiMingDan += $"{tiebaName}|{(string.IsNullOrEmpty(yongHuMing) ? touXiang : yongHuMing)}\r\n"; shiBaiShu++; } } progressBar1.Value = 200; string msg = "批量添加结果如下:\n" + $"总计={(chengGongShu + shiBaiShu + chongFuShu)}个\n" + $"成功={chengGongShu}个\n" + $"失败={shiBaiShu}个\n" + $"重复={chongFuShu}个"; if (shiBaiShu > 0) { msg += "\n失败名单将退回列表,重复用户已被剔除。"; } textBox1.Text = shiBaiMingDan; MessageBox.Show(msg, "笨蛋雪说:", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Information); textBox1.Enabled = true; dateTimePicker2.Enabled = true; button_day_type1.Enabled = true; button_day_type2.Enabled = true; button_day_type3.Enabled = true; button1.Enabled = true; }); }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { JieGou = new FengJinXinXi.JieGou { TouXiang = textBox_touXiang.Text, TiebaName = textBox_tiebaName.Text, ZhuXianZhangHao = textBox_zhuXianZhangHao.Text, XunHuanKaiShiShiJian = dateTimePicker1.Text, XunHuanJieShuShiJian = dateTimePicker2.Text }; //自动获取头像ID if (JieGou.ZhuXianZhangHao.Length > 0 && Tieba.GuoLvTouXiangID(JieGou.TouXiang).Length <= 0) { TiebaMingPianJieGou mingPianJieGou = TiebaWeb.GetTiebaMingPian(JieGou.ZhuXianZhangHao); if (!mingPianJieGou.HuoQuChengGong) { MessageBox.Show("头像ID获取失败,请人工填写或重试", "笨蛋雪说:", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Exclamation); return; } pictureBox1.ImageLocation = $"http://tb.himg.baidu.com/sys/portrait/item/{mingPianJieGou.TouXiang}"; textBox_touXiang.Text = mingPianJieGou.TouXiang; JieGou.TouXiang = mingPianJieGou.TouXiang; if (MessageBox.Show("请查看头像,确定用户信息是否正确", "笨蛋雪说:", buttons: MessageBoxButtons.YesNo, icon: MessageBoxIcon.Information) == DialogResult.No) { return; } } //新建 if (ZhuangTai == ZhuangTaiLeiXing.XinJian) { if (string.IsNullOrEmpty(JieGou.TouXiang)) { MessageBox.Show("请填写头像ID", "笨蛋雪说:", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Exclamation); return; } if (!JieGou.TouXiang.Contains("tb.")) { MessageBox.Show("头像ID格式错误", "笨蛋雪说:", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Exclamation); return; } if (string.IsNullOrEmpty(JieGou.TiebaName)) { MessageBox.Show("请填写贴吧名", "笨蛋雪说:", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Exclamation); return; } } //获取封禁时长 if (Tools.HuoQuFengJinShiChang(dateTimePicker1, dateTimePicker2) <= 0) { MessageBox.Show("封禁时长必须大于0", "笨蛋雪说:", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Exclamation); return; } //新建 if (ZhuangTai == ZhuangTaiLeiXing.XinJian) { TiebaMingPianJieGou mingPianJieGou = TiebaWeb.GetTiebaMingPian(JieGou.TouXiang); if (!mingPianJieGou.HuoQuChengGong) { MessageBox.Show("用户信息获取失败", "笨蛋雪说:", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); return; } //更新任务参数 JieGou.ZhuXianZhangHao = mingPianJieGou.YongHuMing; JieGou.TouXiang = mingPianJieGou.TouXiang; //检查重复 if (Form1.access.GetDataTable($"select * from 封禁列表 where 头像='{JieGou.TouXiang}' and 贴吧名='{JieGou.TiebaName}'").Rows.Count > 0) { MessageBox.Show($"{JieGou.ZhuXianZhangHao}已经在{JieGou.TiebaName}吧添加过了", "笨蛋雪说:", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Asterisk); return; } int jieGuo = Form1.access.DoCommand($"insert into 封禁列表 (用户名,头像,贴吧名,最后封禁时间,循环开始时间,循环结束时间)" + $" values('{JieGou.ZhuXianZhangHao}','{JieGou.TouXiang}','{JieGou.TiebaName}','1970-01-01','{JieGou.XunHuanKaiShiShiJian}','{JieGou.XunHuanJieShuShiJian}')"); if (jieGuo > 0) { Dispose(); } else { MessageBox.Show("添加失败", "笨蛋雪说:", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); } } //编辑 else if (ZhuangTai == ZhuangTaiLeiXing.BianJi) { int jieGuo = Form1.access.DoCommand($"update 封禁列表 set 用户名='{JieGou.ZhuXianZhangHao}',循环开始时间='{JieGou.XunHuanKaiShiShiJian}',循环结束时间='{JieGou.XunHuanJieShuShiJian}' where 头像='{JieGou.TouXiang}' and 贴吧名='{JieGou.TiebaName}'"); if (jieGuo > 0) { Dispose(); } else { MessageBox.Show("更新失败", "笨蛋雪说:", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); } } }
/// <summary> /// 主线程 /// </summary> private void MainThread() { //工作时段 bool gongZuoShiDuan = true; Say("循环封禁任务开始"); while (true) { if (Config.Stop) { break; } //判断是否在工作时间 if (0 <= DateTime.Now.Hour && DateTime.Now.Hour < 1) { if (gongZuoShiDuan)//防止重复输出 { Say("为避开网络高峰,任务将在凌晨1点开始,请保持挂机"); gongZuoShiDuan = false; } //扫描间隔 DengDai(Config.SaoMiaoJianGe); continue; } else { gongZuoShiDuan = true; } //删除过期 int shanChuShu = access.DoCommand($"delete from 封禁列表 where 循环结束时间<'{DateTime.Now:yyyy-MM-dd}'"); if (shanChuShu > 0) { Say($"删除{shanChuShu}条过期任务"); } int weiFengJinShu = 0; int lieBiaoZongShu = listView1.Items.Count; for (int i = 0; i < listView1.Items.Count; i++) { if ((DateTime.Now - Convert.ToDateTime(listView1.Items[i].SubItems[3].Text)).Days > 0) { weiFengJinShu++; } } toolStripStatusLabel1.Text = $"未封禁数:{weiFengJinShu} 列表总数:{lieBiaoZongShu}"; toolStripProgressBar1.Minimum = 0; toolStripProgressBar1.Maximum = lieBiaoZongShu; toolStripProgressBar1.Value = lieBiaoZongShu - weiFengJinShu; //开始遍历 for (int i = 0; i < listView1.Items.Count; i++) { if (Config.Stop) { break; } string dangQianShiJian = DateTime.Now.ToString("yyyy-MM-dd"); string id = listView1.Items[i].SubItems[0].Text; DataTable dt = access.GetDataTable($"select top 1 * from 封禁列表 where ID={id}"); if (dt.Rows.Count == 0) { continue; } string zhuXianZhangHao = Convert.ToString(dt.Rows[0]["用户名"]); string touXiang = Convert.ToString(dt.Rows[0]["头像"]); string tiebaName = Convert.ToString(dt.Rows[0]["贴吧名"]); string zuiHouFengJinShiJian = Convert.ToString(dt.Rows[0]["最后封禁时间"]); if (Convert.ToDateTime(zuiHouFengJinShiJian) >= Convert.ToDateTime(dangQianShiJian)) { continue; } //获取用户信息 if (string.IsNullOrEmpty(zhuXianZhangHao)) { TiebaMingPianJieGou mingPianJieGou = TiebaWeb.GetTiebaMingPian(touXiang); if (mingPianJieGou.HuoQuChengGong) { //更新任务参数 zhuXianZhangHao = Tools.HuoQuZhuXianZhangHao(mingPianJieGou); //写进数据库 string sqlStr = $"update 封禁列表 set 用户名='{zhuXianZhangHao}',头像='{touXiang}' where ID={id}"; if (access.DoCommand(sqlStr) == 0) { Say($"SQL执行失败:{sqlStr}"); } } else { Say($"用户名={zhuXianZhangHao},用户信息获取失败:{mingPianJieGou.Msg}", zhuXianZhangHao, touXiang); DengDai(Config.FengJinJianGe); } } //跳过没有头像的 if (string.IsNullOrEmpty(touXiang)) { continue; } TiebaBaWu baWu = new TiebaBaWu { Cookie = Config.Cookie, TiebaName = tiebaName, Fid = FidHuanCun.GetFid(tiebaName), YongHuMing = zhuXianZhangHao, NiCheng = string.Empty, TouXiang = touXiang }; int day = 1; string liYou = $"由于您违反{tiebaName}吧规定,故封禁1天,如有疑问请联系吧务团队"; //封禁结果 if (baWu.FengJin(day, liYou, out string msg)) { Say($"{zhuXianZhangHao}在{tiebaName}吧,封禁1天成功", zhuXianZhangHao, touXiang); int jieGuo = access.DoCommand($"update 封禁列表 set 最后封禁时间='{dangQianShiJian}' where ID={id}"); if (jieGuo > 0) { listView1.Items[i].SubItems[3].Text = dangQianShiJian; } weiFengJinShu--; toolStripStatusLabel1.Text = $"未封禁数:{weiFengJinShu} 列表总数:{lieBiaoZongShu}"; toolStripProgressBar1.Value = lieBiaoZongShu - weiFengJinShu; //封禁间隔 DengDai(Config.FengJinJianGe); } else { Say($"{zhuXianZhangHao}在{tiebaName}吧,封禁1天失败:{msg} {Config.ChongShiJianGe}秒后重试", zhuXianZhangHao, touXiang); //重试间隔 if (msg == "need vcode") { Say("错误信息:need vcode,账号操作频繁,暂停5分钟后重试"); DengDai(300); } else { DengDai(Config.ChongShiJianGe); } } } //扫描间隔 DengDai(Config.SaoMiaoJianGe); } Say("任务结束"); button3.Text = "开始"; button3.Enabled = true; PiLiangJinYongKongJian(true); }