ARI*_*N V 4 c# bots telegram telegram-bot
我写了一个机器人,询问你的名字并将其写在照片上并发送给你并且它有效.但问题是当僵尸程序上有多个用户时
它无法正常工作并崩溃,我想知道如何分离用户条目和输出.(就像每个连接的用户得到一个单独的会话,因为现在一切都发生在一个会话和它崩溃)这是我的代码:
void bot_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs e)
{
KeyboardButton[] btns = new KeyboardButton[1];
btns[0] = new KeyboardButton("???? ???");
if(e.Message.Text=="???? ???")
{
bot.SendTextMessageAsync(e.Message.From.Id, "??? ??? ?? ???? ????", Telegram.Bot.Types.Enums.ParseMode.Default, false, false, 0);
// e.Message.Text = null;
shart = 1;
}
else
{
if (shart == 0)
{
Telegram.Bot.Types.ReplyMarkups.ReplyKeyboardMarkup markup = new Telegram.Bot.Types.ReplyMarkups.ReplyKeyboardMarkup(btns);
bot.SendTextMessageAsync(e.Message.From.Id, "???? ???? ? ???? ??? ??? ???? ???? ??? ???? ????", Telegram.Bot.Types.Enums.ParseMode.Default, false, false, 0, markup);
}
if (shart==1)
{
bot.StartReceiving();
bot.OnMessage += bot_OnMessage1;
}
}
}
void bot_OnMessage1(object sender, Telegram.Bot.Args.MessageEventArgs a)
{
string watermarkText = a.Message.Text;
//Get the file name.
string fileName = "C:\\temp\\01.jpg";
//Read the File into a Bitmap.
using (Bitmap bmp = new Bitmap(fileName))
{
using (Graphics grp = Graphics.FromImage(bmp))
{
//Set the Color of the Watermark text.
Brush brush = new SolidBrush(Color.White);
//Set the Font and its size.
Font font = new System.Drawing.Font("Arial", 50, FontStyle.Bold, GraphicsUnit.Pixel);
//Determine the size of the Watermark text.
SizeF textSize = new SizeF();
textSize = grp.MeasureString(watermarkText, font);
//Position the text and draw it on the image.
Point position = new Point((bmp.Width - ((int)textSize.Width + 10)), (bmp.Height - ((int)textSize.Height + 10)));
grp.DrawString(watermarkText, font, brush, position);
bmp.Save("c:\\temp\\postpic.jpg", ImageFormat.Png);
using (FileStream fs = new FileStream("c:\\temp\\postpic.jpg", FileMode.Open))
{
fs.CanTimeout.ToString();
FileToSend fileToSend = new FileToSend("postpic.jpg", fs);
// var = FileToSend fts = new FileToSend("postpic", fs);
var rep = bot.SendPhotoAsync(a.Message.From.Id, fileToSend, "??? ??? ?? ??? ????").Result;
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
您正在为每个用户编写(并随后读取)相同的文件:
mp.Save("c:\\temp\\postpic.jpg"
Run Code Online (Sandbox Code Playgroud)
您需要为每个用户提供唯一的文件名.或者更好的是,根本不要使用文件.您可能只是使用本地内存流而根本不会使用文件混乱磁盘.
| 归档时间: |
|
| 查看次数: |
788 次 |
| 最近记录: |