나는 당신의 이름을 묻고 그것을 사진에 쓰고 당신에게 보내는 봇을 썼다. 하지만 문제는 봇에 둘 이상의 사용자가있는 경우입니다.
작동하지 않고 충돌이 발생하고 사용자 항목과 출력을 분리하는 방법을 알고 싶습니다. (연결되는 각 사용자가 분리 된 세션을 얻는 것처럼 모든 것이 발생하므로C#의 Telegram 봇에서 여러 사용자를 처리하는 방법은 무엇입니까?
mp.Save("c:\\temp\\postpic.jpg"
당신이 필요합니다 : 당신은 서면으로 (그리고 이후 각 사용자에 대해)에서 매우 동일한 파일 을 읽고
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;
}
}
}
}
}
플랫폼 당신이이 글을 쓰는되어 https://t.me/DebtsTrackerBot에 채무 기록을 만드는 동안 사용이 방법을 어디는에서의 연결합니까? –
아웃 이미지 파일을 작성할 때 하드 코딩 된 파일 이름 인 "c : \ temp \\ postpic.jpg"를 사용하는 것 같습니다. 여러 사용자가 액세스하는 동안 문제가 발생합니다. 대신 사용자 이름과 타임 스탬프를 사용하여 out 파일 이름을 생성하십시오. fileName = string.Format ("c : \\ temp \\ postpic_ {0} .jpg", DateTime.Now.ToString ("ddMMyyyy-HHmmss")); –