33using System . Threading . Tasks ;
44using Discord ;
55using Discord . WebSocket ;
6+ using Microsoft . EntityFrameworkCore ;
67
78public class Program
89{
@@ -26,6 +27,12 @@ private Program(
2627
2728 public static async Task Main ( string [ ] args )
2829 {
30+ var dbOptions = new DbContextOptionsBuilder < DphContext > ( ) . UseSqlite ( $ "Data Source={ System . IO . Path . Join ( AppContext . BaseDirectory , "data_storage.db" ) } ") . Options ;
31+ using ( var db = new DphContext ( dbOptions ) )
32+ {
33+ db . Database . EnsureCreated ( ) ;
34+ }
35+
2936 string token = null ;
3037 bool auto = false ;
3138
@@ -98,6 +105,8 @@ private async Task RunAsync()
98105
99106 private async Task ConsoleLoopAsync ( )
100107 {
108+ ConsoleCommand cmd = new ( ) ;
109+
101110 while ( true )
102111 {
103112 #region Experimental Console
@@ -111,7 +120,7 @@ private async Task ConsoleLoopAsync()
111120 // case ConsoleKey.Enter:
112121 // goto break_input_loop;
113122 // break;
114-
123+
115124 // case ConsoleKey.Backspace:
116125 // if (input.Length < 1) break;
117126 // input = input[0..^1];
@@ -135,7 +144,7 @@ private async Task ConsoleLoopAsync()
135144
136145 var input = Console . ReadLine ( ) ;
137146
138- if ( await EvaluateInputAsync ( input ) ) break ;
147+ if ( await EvaluateInputAsync ( cmd , input ) ) break ;
139148 }
140149
141150 _ = Logger . Log ( "Bot shutting down." , LogSeverity . Info ) ;
@@ -147,12 +156,12 @@ private async Task ConsoleLoopAsync()
147156 /// </summary>
148157 /// <param name="input"></param>
149158 /// <returns>Should exit console loop</returns>
150- private async Task < bool > EvaluateInputAsync ( string input )
159+ private async Task < bool > EvaluateInputAsync ( ConsoleCommand cmd , string input )
151160 {
152- ConsoleCommand cmd = new ( ) ;
153161 string [ ] processedInput = input . Split ( ' ' ) ;
154162 bool shouldConsoleLoopExit = false ;
155163
164+ // TODO Put the switch in the ConsoleCommand class
156165 switch ( processedInput [ 0 ] )
157166 {
158167 case "help" :
@@ -179,7 +188,7 @@ private async Task<bool> EvaluateInputAsync(string input)
179188 _ = Logger . Log ( "Too many arguments for this command!" , LogSeverity . Error ) ;
180189 break ;
181190 }
182- shouldConsoleLoopExit = await cmd . Exit ( client ) ;
191+ shouldConsoleLoopExit = await cmd . Exit ( client ) ;
183192 break ;
184193
185194 case "reload-config" :
@@ -196,8 +205,8 @@ private async Task<bool> EvaluateInputAsync(string input)
196205 {
197206 _ = Logger . Log ( "Too many arguments for this command!" , LogSeverity . Error ) ;
198207 break ;
199- }
200- else if ( processedInput . Length < 2 )
208+ }
209+ else if ( processedInput . Length < 2 )
201210 {
202211 _ = Logger . Log ( "Too many arguments for this command!" , LogSeverity . Error ) ;
203212 break ;
@@ -257,7 +266,7 @@ private async Task<bool> EvaluateInputAsync(string input)
257266 break ;
258267
259268 default :
260- invalid_input :
269+ invalid_input :
261270 Console . Write ( $ "\x1b [1F\x1b [K\x1b [31m'{ input } ' is not a valid command.\x1b [0m\n ") ;
262271 break ;
263272 }
0 commit comments