summaryrefslogtreecommitdiff
path: root/bot.js
blob: 53585a5645f11d739c5a3cf3270fb294c3f04c66 (plain) (blame)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/****************************************
 * 
 *   Oswald: A bot made from discord.js and crafted for Mr.Blue's Fanbase and based of AleeBot 1.0.9
 *   Copyright (C) 2018 Alee14
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * *************************************/
const Discord = require('discord.js');
const client = new Discord.Client();
const config = require('./config.json');

var prefix = "oswald:";
var version = "1.0.0";

client.on('ready', () => {
       console.log("[SUCCESS] Oswald is now ready! Running version "+ version +"!");
       client.user.setStatus('online')
   });

client.on("guildCreate", guild => {

  // This event triggers when the bot joins a guild.

  console.log(`New guild joined: ${guild.name} (id: ${guild.id}). This guild has ${guild.memberCount} members!`);

});



client.on("guildDelete", guild => {

  // this event triggers when the bot is removed from a guild.

  console.log(`I have been removed from: ${guild.name} (id: ${guild.id})`);


});


client.on("message", function(message){
  if (message.author.bot) return;
  if (message.channel.type === "dm") return;
  if (!message.content.startsWith(prefix)) return;


  let command = message.content.split(" ")[0];
  command = command.slice(prefix.length);

  let args = message.content.split(" ").slice(1);

	 if (command === 'help'){
		 var embed = new Discord.RichEmbed()
            .setTitle(`Commands for Oswald ` + version + `.`)
            .setDescription('Every command you put in this bot must start with `'+ prefix + '`')
          .addField('Fun Stuff:', 'attack\nask\nship',true)
          .addField('Moderation', 'ban\nkick',true)
            .addField('Link:', 'git',true)
            .addField('Owner Only:', 'say',true)
            .addField('Monitor:', 'ping\nuptime',true)
            .addField('Etc:', 'avatarurl', true)
			.setFooter("Oswald "+ version +" Copyright 2018. Created by Alee14", "https://cdn.discordapp.com/avatars/282547024547545109/6c147a444ae328c38145ef1f74169e38.png?size=2048")
			.setColor("#7af442")
			message.channel.send({embed});

    }
    
    if(command === 'avatarurl'){
        message.reply(message.author.avatarURL);
    }

    if(command === 'git'){
        message.channel.send ("Here's the github repo: https://github.com/Alee14/Oswald/");
    } 

    if(command === 'ping'){
        message.reply("**PONG!** :ping_pong: " + Math.round(client.ping) + " ms");
    }


    if(command === 'uptime'){
      //This command was ported from AstralMod
      var timeString; // What we'll eventually put into the message

      var uptime = parseInt(client.uptime); // Get uptime in ms

      uptime = Math.floor(uptime / 1000); // Convert from ms to s

      var uptimeMinutes = Math.floor(uptime / 60); // Get the uptime in minutes

      var minutes = uptime % 60;

      var hours = 0;

      while (uptimeMinutes >= 60) {

      hours++;

      uptimeMinutes = uptimeMinutes - 60;

     }



    if (uptimeMinutes < 10) {

        timeString = hours + ":0" + uptimeMinutes // We need to add an additional 0 to the minutes

    } else {

        timeString = hours + ":" + uptimeMinutes // We don't need to add an extra 0.

    }

    message.reply(":clock1: Oswald has been up for " + timeString + " hours.");

commandProcessed = true;
    }

    if(command === 'attack'){
      //This command was ported from AstralMod
        if (command.indexOf("@everyone") == -1) {
           if (command.indexOf("@here") == -1) {
                message.channel.send("<@" + message.author.id + "> :right_facing_fist: " + args);
            } else {
            message.reply("Nice try, but I ain't going to interrupt everyone who is online at this time. Kinda nice to not be bothered.");
          }
             } else {
                message.reply("Nice try, but I ain't going to interrupt everyone. Kinda nice to not be bothered.");
              }
                        }
      if(command === 'ask'){
        var abaskanswer = [
          "Yes.",
          "Nope. Just kidding :P",
          "Definitely!",
          "No.",
          "Yep. Just kidding :P",
          "I doubt it.",
          "Maybe?",
          "I don't know?",
          "Hmm let me think :thinking:"
        ];
        if (args[1]) {
           message.channel.sendMessage(abaskanswer[Math.floor(Math.random() * abaskanswer.length)]);
        } else {
          message.channel.sendMessage("Sorry, I don't know what your saying.")
        }

      }
// Owner is only allow to do this
    if(command === 'say'){
      if(message.author.id !== config.ownerID) return message.reply('You need Mr. Blue for this.');
      message.channel.sendMessage(args.join(" "));
      message.delete();

    }
    if(command === 'ship'){
      message.channel.send(":ship: "+ message.author.username + " x " + message.guild.members.random().displayName);
    }

    if(command === 'ban'){
        const mreason = args.join(" ").slice(22);
        if (!message.member.permissions.has('BAN_MEMBERS')) return message.reply("It looks like that you don't have the permissions to ban people.")
        if (!message.guild.member(client.user).hasPermission('BAN_MEMBERS')) return message.reply('Uhh... I don\'t have permission to ban members.');
        const member = message.mentions.members.first();
        if (!member) return message.reply("Uhh... Please mention a member first.");
        member.ban(`Banned by ${message.author.tag} Reason: ` + mreason);
        message.reply(`**${member.user.tag}** has been banned for the reason: \n\`\`\`${mreason}.\`\`\`\n`);
    }

    if(command === 'kick'){
      const mreason = args.join(" ").slice(22);
      if (!message.member.permissions.has('KICK_MEMBERS')) return message.reply("It looks like that you don't have the permissions to ban people.");
      if (!message.guild.member(client.user).hasPermission('KICK_MEMBERS')) return message.reply('Uhh... I don\'t have permission to kick members.');
      const member = message.mentions.members.first();
      if (!member) return message.reply("Uhh... Please mention a member first.");
      member.kick(`Kicked by: ${message.author.tag} Reason: ` + mreason);
      message.reply(`**${member.user.tag}** has been kicked for the reason: \n\`\`\`${mreason}.\`\`\`\n`);
    }


 });

const clean = text => {
  if (typeof(text) === "string")
    return text.replace(/`/g, "`" + String.fromCharCode(8203)).replace(/@/g, "@" + String.fromCharCode(8203));
  else
      return text;
}

 process.on('unhandledRejection', function(err, p) {
   console.log("[ERROR | UNCAUGHT PROMISE] " + err.stack);
});

 client.login (config.token).catch(function() {
       console.log("[ERROR] Login failed. Please contact Alee14#9928 or email him at alee14498@gmail.com.");
});