(String[] args)
| 39 | private static Database database = null; |
| 40 | |
| 41 | public static void main(String[] args) throws LoginException { |
| 42 | String token = null; |
| 43 | try { |
| 44 | File tokenFile = Paths.get("token.txt").toFile(); |
| 45 | if (!tokenFile.exists()) { |
| 46 | System.out.println("[ERROR] Could not find token.txt file"); |
| 47 | System.out.print("Please paste in your bot token: "); |
| 48 | Scanner s = new Scanner(System.in); |
| 49 | token = s.nextLine(); |
| 50 | System.out.println(); |
| 51 | System.out.println("[INFO] Creating token.txt - please wait"); |
| 52 | if (!tokenFile.createNewFile()) { |
| 53 | System.out.println( |
| 54 | "[ERROR] Could not create token.txt - please create this file and paste in your token" |
| 55 | + "."); |
| 56 | s.close(); |
| 57 | return; |
| 58 | } |
| 59 | Files.write(tokenFile.toPath(), token.getBytes()); |
| 60 | s.close(); |
| 61 | } |
| 62 | token = new String(Files.readAllBytes(tokenFile.toPath())); |
| 63 | } catch (Exception ex) { |
| 64 | ex.printStackTrace(); |
| 65 | } |
| 66 | if (token == null) return; |
| 67 | if (enableDatabase) database = new Database(dbType); |
| 68 | if (database != null) { |
| 69 | if (!database.isConnected()) { |
| 70 | database = null; |
| 71 | System.out.println("[ERROR] Database connection failed. Continuing without database."); |
| 72 | } else { |
| 73 | database.update( |
| 74 | "CREATE TABLE IF NOT EXISTS guildprefix (guildId VARCHAR(18) NOT NULL, prefix VARCHAR(8) NOT " |
| 75 | + "NULL);"); |
| 76 | } |
| 77 | } |
| 78 | List<GatewayIntent> intents = new ArrayList<>( |
| 79 | Arrays.asList(GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_EMOJIS, |
| 80 | GatewayIntent.GUILD_MESSAGE_REACTIONS)); |
| 81 | DefaultShardManagerBuilder builder = DefaultShardManagerBuilder.create(token, intents); |
| 82 | builder.setStatus(OnlineStatus.ONLINE); |
| 83 | builder.setActivity(Activity.playing("@Sokobot for info!")); |
| 84 | builder.addEventListeners(new GameListener(), new CommandListener()); |
| 85 | builder.disableCache( |
| 86 | CacheFlag.CLIENT_STATUS, CacheFlag.ACTIVITY, CacheFlag.MEMBER_OVERRIDES, CacheFlag.VOICE_STATE); |
| 87 | shardManager = builder.build(); |
| 88 | GameUtil.runGameTimer(); |
| 89 | Thread consoleThread = new Thread(() -> { |
| 90 | Scanner s = new Scanner(System.in); |
| 91 | while (s.hasNextLine()) { |
| 92 | processCommand(s.nextLine()); |
| 93 | } |
| 94 | }); |
| 95 | consoleThread.setDaemon(true); |
| 96 | consoleThread.setName("Console Thread"); |
| 97 | consoleThread.start(); |
| 98 | } |
nothing calls this directly
no test coverage detected