137 lines
4.0 KiB
C#
137 lines
4.0 KiB
C#
using Api.Framework;
|
||
using Api.Framework.Model;
|
||
using Api.Framework.SDK;
|
||
using Api.Framework.Tools;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
using 循环的发消息.Properties;
|
||
|
||
namespace 循环的发消息
|
||
{
|
||
public class Class1 : Plugin
|
||
{
|
||
public Class1()
|
||
{
|
||
this.Logo = Resources._1;
|
||
this.Name = "循环发送";
|
||
this.Note = "";
|
||
}
|
||
|
||
#region 自定义变量
|
||
public static Config Config;
|
||
private Form1 mainForm = null;
|
||
#endregion
|
||
|
||
public override void Start()
|
||
{
|
||
try
|
||
{
|
||
//创建配置文件
|
||
Config = this.ReadConfig<Config>();
|
||
|
||
SDK.ReciveIMEvent += SDK_ReciveIMEvent;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog(ex.Message);
|
||
}
|
||
}
|
||
|
||
static bool state = false;
|
||
static bool stop = false;
|
||
private void SDK_ReciveIMEvent(object sender, ReciveIMEvent e)
|
||
{
|
||
try
|
||
{
|
||
if (e.Message == "b")
|
||
stop = true;
|
||
if (e.Message == "a")
|
||
{
|
||
this.OnLog("开始发送...");
|
||
if (!state)
|
||
{
|
||
var t1 = new Task(() =>
|
||
{
|
||
try
|
||
{
|
||
state = true;
|
||
if (string.IsNullOrWhiteSpace(Config.Users)) throw new Exception("用户不能为空");
|
||
|
||
var users = Config.Users.Replace(",", ",").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(f => f.Trim()).ToList();
|
||
|
||
var messs = Config.Content.Split(new string[] { "[分段]" }, StringSplitOptions.RemoveEmptyEntries);
|
||
|
||
for (int i = 0; i < Class1.Config.Num; i++)
|
||
{
|
||
foreach (var mess in messs)
|
||
{
|
||
foreach (var m in users)
|
||
{
|
||
ApiClient.SendMessage(e.RobotInfo, m, mess);
|
||
Thread.Sleep(Config.Sleep);
|
||
if (stop)
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{ }
|
||
finally
|
||
{
|
||
stop = false;
|
||
state = false;
|
||
}
|
||
}, TaskCreationOptions.LongRunning);
|
||
|
||
t1.Start();
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog(ex.Message);
|
||
}
|
||
}
|
||
|
||
public override void ShowForm()
|
||
{
|
||
try
|
||
{
|
||
if (mainForm == null || mainForm.IsDisposed)
|
||
{
|
||
mainForm = new Form1();
|
||
mainForm.Show();
|
||
}
|
||
mainForm.TopMost = true;
|
||
mainForm.TopMost = false;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog(ex.Message);
|
||
}
|
||
}
|
||
|
||
public override void Stop()
|
||
{
|
||
try
|
||
{
|
||
if (mainForm != null)
|
||
{
|
||
mainForm.CloseForm();
|
||
mainForm = null;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog(ex.Message);
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|