Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCafeController.cs
More file actions
Latest commit
123 lines (111 loc) · 4.67 KB
/
Copy pathCafeController.cs
File metadata and controls
123 lines (111 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
usingSystem.Text;
usingTelegram.Bot;
usingSixLabors.ImageSharp;
usingTelegramBot.Builders;
usingTelegramBot.Attributes;
usingTelegramBot.Controllers;
usingTelegramBot.Abstractions;
usingSixLabors.ImageSharp.PixelFormats;
namespaceTelegramBot.ConsoleTest.Controllers
{
publicclassCafeController(ITelegramBotClienttelegramBotClient):BotControllerBase
{
constlongchiefUserId=123;// Replace with the actual user ID of the chief in restaurant
[TextCommand("/burgers")]
publicIActionResultHandleBurgers()
{
KeyboardBuilderbuilder=new();
builder
.WithColumns(2)
.AddButton("🍔","/burgers/1/drink/false")
.AddButton("🍔🍔","/burgers/2/drink/false")
.AddButton("🍔🥤","/burgers/1/drink/true")
.AddButton("🍔🍔🥤","/burgers/2/drink/true");
returnInline("Choose your order:",builder.Build());
}
[InlineCommand("/burgers/{burgers}/drink/{drink}")]
publicasyncTask<IActionResult>HandleBurgersAsync(intburgers,booldrink)
{
constintburgerPrice=5;
constintdrinkPrice=2;
intcookTime=Random.Shared.Next(18,35);
inttotalPrice=(burgers*burgerPrice)+(drink?drinkPrice:0);
stringtext="🍽🍽🍽🍽🍽🍽🍽🍽🍽🍽🍽🍽\n"+
"Vadim's Burgers got your order!\n\n"+
"Your order:\n"+
$"🍔 {burgers}x Vadim's Burger\n"+
(drink?"🥤 1x Drink\n":"No drink\n\n")+
$"Total: ${totalPrice}.00\n\n"+
"The best burgers will be ready in "+cookTime+" minutes\n"+
"🍽🍽🍽🍽🍽🍽🍽🍽🍽🍽🍽🍽";
stringsender=Update.Message?.From?.Username??"Anonymous";
stringorderText=$"Order from {sender}:\n"+
$"🍔 {burgers}x Vadim's Burger\n"+
(drink?"🥤 1x Drink\n":"No drink\n")+
$"Total: ${totalPrice}.00\n"+
"Send /burgersdone when you are ready to pick up";
awaittelegramBotClient.SendMessage(chiefUserId,orderText);
SetValue("customerId",User.Id);
returnMultiAction(
Text(text),
DeleteMessage()
);
}
[TextCommand("/burgersdone")]
publicasyncTask<IActionResult>HandleBurgersDoneAsync()
{
conststringtext="🍽🍔🥤🍔🥤🍔🍽\n\n"+
"Your order is ready!\n"+
"Please pick up your order at the living room.\n"+
"Enjoy your meal!\n\n"+
"🍽🍔🥤🍔🥤🍔🍽";
longcustomerId=GetValue<long>("customerId");
if(customerId==0)
{
returnText("You have no active orders");
}
awaittelegramBotClient.SendMessage(customerId,text);
returnText(text);
}
[TextCommand("/receipt")]
publicIActionResultHandleReceipt()
{
vartextFileStream=WriteFile();
varimageStream=DrawImage();
returnMultiAction(
File(textFileStream,"receipt.txt"),
Image(imageStream,"Receipt Image"));
}
privatestaticMemoryStreamWriteFile()
{
StringBuilderstringBuilder=new();
stringBuilder.AppendLine("Date: 2021-09-01");
stringBuilder.AppendLine("Time: 12:00");
stringBuilder.AppendLine("Order: 2x Vadim's Burger");
stringBuilder.AppendLine("Total: $10.00");
stringBuilder.AppendLine("Payment method: Cash");
stringBuilder.AppendLine("Thank you for your order!");
MemoryStreamfileStream=new(Encoding.UTF8.GetBytes(stringBuilder.ToString()));
returnfileStream;
}
privatestaticMemoryStreamDrawImage()
{
constbytesize=byte.MaxValue;
usingImage<Rgba32>image=new(size,size,Color.Gray);
for(intx=0;x<image.Width;x++)
{
for(inty=0;y<image.Height;y++)
{
byter=(byte)(x%size);
byteg=(byte)(y%size);
byteb=(byte)(((x+y)/2)%size);
image[x,y]=newRgba32(r,g,b);
}
}
MemoryStreamimageStream=new();
image.SaveAsJpegAsync(imageStream);
imageStream.Position=0;
returnimageStream;
}
}
}